kolibrios-gitea/contrib/sdk/sources/libsync/m_lock.asm
Sergey Semyonov (Serge) 1918b713af newlib: struct dirent
pixlib3: enable linear texture filtration
libsync: user space synchronization

git-svn-id: svn://kolibrios.org@5602 a494cfbc-eb01-0410-851d-a64ba20cac60
2015-07-23 10:10:52 +00:00

42 lines
794 B
NASM

format MS COFF
use32
MUTEX.lock equ 0
MUTEX.handle equ 4
section '.text' align 16 code readable executable
public @mutex_lock@4
@mutex_lock@4:
mov eax, 1
lock xadd [ecx+MUTEX.lock], eax
test eax, eax
jnz .slow
ret
.slow:
push ebx
push esi
push edi
mov edi, ecx
mov ecx, [edi+MUTEX.handle]
mov edx, 2
mov ebx, edx
xor esi, esi
align 4
.again:
mov eax, edx
xchg eax, [edi+MUTEX.lock]
test eax, eax
jz .ok
mov eax, 77
int 0x40
jmp .again
.ok:
pop edi
pop esi
pop ebx
ret