Aktív témák

  • P.H.

    senior tag

    Többszálú pufferkezelési kód. Lehetne jobb is... (?)

    function _WAITTHREADS: DWORD;
    asm test eax,eax
    pushad
    mov ebx,esp
    jz @return
    xor ebp,ebp
    @threadarray:
    shr eax,01h
    lea edx,[edx+TBUFFERSIZE]
    jnc @threadarray
    lea ebp,[ebp+01h]
    push dword ptr [edx+TBUFFER.THREAD]
    jnz @threadarray
    mov edx,esp
    push INFINITE; push ecx; push edx; push ebp; call WINDOWS.WAITFORMULTIPLEOBJECTS
    mov esp,ebx
    @return:
    popad
    test eax,eax end;
    procedure _RESTARTBUFFERS;
    asm pushad
    mov edx,offset(BUFFERS)
    mov bl,cBUFFER
    xor ebp,ebp
    mov eax,[PENDINGS]; mov ecx,01h; sub edx,TBUFFERSIZE; call _WAITTHREADS
    mov esi,edx
    mov edi,eax
    @init:
    sub bl,cl
    lea esi,[esi+TBUFFERSIZE]
    js @return
    shr edi,cl
    jc @init
    mov edx,esi; call _BUF0
    jmp @init
    @return:
    mov [PENDINGS],ebp
    mov [LOCKBITS],ebp
    popad end;
    procedure _ZEROBUFFER(Blank,Buffer:pointer);
    asm cmp byte ptr [_INSSET+__CPUS],01h
    mov ecx,[edx+TBUFFER.BIT]
    ja @moreCPU
    xor ecx,-1
    and [LOCKBITS],ecx
    jmp _BUF0
    @moreCPU:
    push ebx
    lea ebx,[edx+TBUFFER.THREAD]
    lock or [PENDINGS],ecx
    push ebx; push 00h; push edx; push offset(@ZTHREAD); push 60h; push 00h; call CREATETHREAD
    mov [ebx],eax
    pop ebx
    ret
    @ZTHREAD:
    { ESP+04h: TBUFFER structure
    mov edx,[esp+04h]
    or ecx,-1
    xor ecx,[edx+TBUFFER.BIT]
    call _BUF0
    lock and [LOCKBITS],ecx
    lock and [PENDINGS],ecx
    ret 04h end;
    procedure _FREEBUFFER(Value:pHGLOBAL);
    asm mov edx,eax
    xor ecx,ecx
    mov eax,[eax]
    mov [edx],ecx
    test eax,eax
    mov edx,offset(BUFFERS)
    jz @return
    @search:
    cmp eax,[edx+TBUFFER.ADDR]
    jz _ZEROBUFFER
    add ecx,01h
    add edx,TBUFFERSIZE
    cmp ecx,cBUFFER
    jb @search
    mov eax,[_NOFREE]
    jmp ERRORFORM
    @return: end;
    function _GETBUFFER(Dest:pHGLOBAL): HGLOBAL;
    asm pushad
    mov esi,offset(BUFFERS)
    mov edi,_hINV
    sub esi,TBUFFERSIZE
    @testbuffers:
    mov ebp,[LOCKBITS]
    mov ebx,00000001h
    mov edx,esi
    mov cl,cBUFFER
    mov eax,[PENDINGS]
    @search:
    test ebp,ebx
    lea edx,[edx+TBUFFERSIZE]
    jz @lock
    sub cl,01h
    lea ebx,[ebx+ebx]
    jg @search
    xor ecx,ecx; call _WAITTHREADS
    jnz @testbuffers
    popad
    mov eax,[_NOGET]; call ERRORFORM
    xor eax,eax
    ret
    @lock:
    mov esi,[esp+_EAX]
    mov eax,[edx+TBUFFER.ADDR]
    mov ecx,[edx+TBUFFER.THREAD]
    mov [edx+TBUFFER.THREAD],edi
    mov [esi],eax
    lock or [LOCKBITS],ebx
    push ecx; call WINDOWS.CLOSEHANDLE
    popad
    mov eax,[eax] end;

    [ Szerkesztve ]

    Arguing on the Internet is like running in the Special Olympics. Even if you win, you are still ... ˙˙˙ Real Eyes Realize Real Lies ˙˙˙

Aktív témák