diff --git a/kernel/branches/Kolibri-acpi/core/dll.inc b/kernel/branches/Kolibri-acpi/core/dll.inc index 4b9fad92f..e4f8eaa6f 100644 --- a/kernel/branches/Kolibri-acpi/core/dll.inc +++ b/kernel/branches/Kolibri-acpi/core/dll.inc @@ -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 diff --git a/kernel/branches/Kolibri-acpi/core/memory.inc b/kernel/branches/Kolibri-acpi/core/memory.inc index 42f156725..aebf4af68 100644 --- a/kernel/branches/Kolibri-acpi/core/memory.inc +++ b/kernel/branches/Kolibri-acpi/core/memory.inc @@ -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 + diff --git a/kernel/branches/Kolibri-acpi/core/syscall.inc b/kernel/branches/Kolibri-acpi/core/syscall.inc index 9f7b4b6c4..d87fcd1df 100644 --- a/kernel/branches/Kolibri-acpi/core/syscall.inc +++ b/kernel/branches/Kolibri-acpi/core/syscall.inc @@ -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