kolibri-acpi: preliminary futex support

git-svn-id: svn://kolibrios.org@5585 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2015-07-20 13:16:37 +00:00
parent 47d756fe2f
commit 8b61a2e72d
3 changed files with 100 additions and 4 deletions

View File

@ -1393,19 +1393,21 @@ create_object:
align 4
;struct futex* __fastcall create_futex(int *ptr)
create_futex:
push ecx
mov ecx, sizeof.FUTEX
call create_object
pop ecx
test eax, eax
jz .fail
mov [eax+FUTEX.magic], 'FUTX'
mov [eax+FUTEX.destroy], 0
mov [eax+FUTEX.pointer], ecx
lea ecx, [eax+FUTEX.wait_list]
list_init ecx
mov [eax+FUTEX.pointer], 0
mov [eax+FUTEX.flags], 0
.fail:
ret

View File

@ -1171,8 +1171,6 @@ endp
align 4
sysfn_meminfo:
; add ecx, new_app_base
cmp ecx, OS_BASE
jae .fail
@ -1448,3 +1446,97 @@ proc print_mem
.done:
ret
endp
FUTEX_INIT equ 0
FUTEX_WAIT equ 1
FUTEX_WAKE equ 2
align 4
f77call:
dd f77.futex_init ;0
dd f77.futex_wait ;1
dd f77.futex_wake ;2
align 4
sys_synchronization:
f77:
cmp ebx, FUTEX_WAKE
ja .fail
jmp dword [f77call+ebx*4]
.fail:
mov [esp+32], dword 0
ret
align 4
.futex_init:
call create_futex
test eax, eax
jz @F
mov eax, [eax+FUTEX.handle]
@@:
mov [esp+32], eax
ret
align 4
.futex_wait:
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
mov ecx, [edi+FUTEX.pointer]
mov edx, 1
mov eax, [ecx]
test eax, eax
jnz .wait_slow
lock cmpxchg [ecx], edx
jz .ok
.wait_slow:
pushfd
cli
sub esp, sizeof.MUTEX_WAITER
mov ebx, [TASK_BASE]
mov [ebx+TASKDATA.state], 1
mov [esp+MUTEX_WAITER.task], ebx
lea esi, [edi+FUTEX.wait_list]
list_add_tail esp, esi ;esp= new waiter, esi= list head
.again:
call change_task
mov eax, [ecx]
test eax, eax
jnz .again
lock cmpxchg [ecx], edx
jnz .again
list_del esp
add esp, sizeof.MUTEX_WAITER
popfd
.ok:
mov [esp+32], eax
ret
.epicfail:
mov [esp+32], dword -1
ret
align 4
.futex_wake:
ret

View File

@ -175,6 +175,8 @@ iglobal
dd sys_network ; 74-reserved for new stack
dd sys_socket ; 75-reserved for new stack
dd sys_protocols ; 76-reserved for new stack
dd sys_synchronization ; 77
times 255 - ( ($-servetable2) /4 ) dd undefined_syscall
dd sys_end ; -1-end application