kolibri-acpi: FUTEX_WAKE

git-svn-id: svn://kolibrios.org@5590 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2015-07-20 19:48:12 +00:00
parent 2cfbdba0b0
commit 951d3fdb52
2 changed files with 60 additions and 13 deletions

View File

@ -1481,6 +1481,8 @@ align 4
ret ret
align 4 align 4
;ecx futex handle
;edx new value
.futex_wait: .futex_wait:
cmp ecx, 3 cmp ecx, 3
jb .epicfail jb .epicfail
@ -1496,12 +1498,13 @@ align 4
jne .epicfail jne .epicfail
mov ecx, [edi+FUTEX.pointer] mov ecx, [edi+FUTEX.pointer]
mov edx, 1
mov eax, [ecx] mov eax, edx
test eax, eax lock cmpxchg [ecx], edx ;wait until old_value == new_value
jnz .wait_slow jz .wait_slow
lock cmpxchg [ecx], edx
jz .ok mov [esp+SYSCALL_STACK._eax], 0
ret
.wait_slow: .wait_slow:
pushfd pushfd
@ -1518,25 +1521,56 @@ align 4
.again: .again:
call change_task call change_task
mov eax, [ecx]
test eax, eax
jnz .again
lock cmpxchg [ecx], edx lock cmpxchg [ecx], edx
jnz .again jz .again
list_del esp list_del esp
add esp, sizeof.MUTEX_WAITER add esp, sizeof.MUTEX_WAITER
popfd popfd
.ok: mov [esp+SYSCALL_STACK._eax], 0
mov [esp+32], eax
ret ret
.epicfail: .epicfail:
mov [esp+32], dword -1 mov [esp+SYSCALL_STACK._eax], -1
ret ret
align 4 align 4
.futex_wake: .futex_wake:
cmp ecx, 3
jb .epicfail
cmp ecx, (PROC.pdt_0 - PROC.htab)/4
jae .epicfail
mov esi, [current_process]
mov edi, [esi+PROC.htab+ecx*4]
cmp [edi+FUTEX.magic], 'FUTX'
jne .epicfail
cmp [edi+FUTEX.handle], ecx
jne .epicfail
xor ecx, ecx
pushfd
cli
lea ebx, [edi+FUTEX.wait_list]
mov esi, [edi+FUTEX.wait_list.next]
@@:
cmp esi, ebx
je @F
mov eax, [esi+MUTEX_WAITER.task]
mov [eax+TASKDATA.state], 0
mov esi, [esi+MUTEX_WAITER.list.next]
inc ecx
cmp ecx, edx
jb @B
@@:
popfd
mov [esp+SYSCALL_STACK._eax], ecx
ret ret

View File

@ -202,6 +202,19 @@ struct IDE_DEVICE
UDMA_set_mode db ? UDMA_set_mode db ?
ends ends
struct SYSCALL_STACK
_eip dd ?
_edi dd ? ; +4
_esi dd ? ; +8
_ebp dd ? ; +12
_esp dd ? ; +16
_ebx dd ? ; +20
_edx dd ? ; +24
_ecx dd ? ; +28
_eax dd ? ; +32
ends
; Core functions ; Core functions
include "core/sync.inc" ; macros for synhronization objects include "core/sync.inc" ; macros for synhronization objects
include "core/sys32.inc" ; process management include "core/sys32.inc" ; process management