From f5f30ba22641c9579fef7d11d609d99095b59c76 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Thu, 23 Jul 2015 06:55:21 +0000 Subject: [PATCH] kolibri-acpi: futex_wait_timeout git-svn-id: svn://kolibrios.org@5599 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/Kolibri-acpi/core/sched.inc | 17 ++-- kernel/branches/Kolibri-acpi/core/sync.inc | 91 ++++++++++++++++++--- kernel/branches/Kolibri-acpi/gui/event.inc | 6 +- kernel/branches/Kolibri-acpi/macros.inc | 5 -- 4 files changed, 95 insertions(+), 24 deletions(-) diff --git a/kernel/branches/Kolibri-acpi/core/sched.inc b/kernel/branches/Kolibri-acpi/core/sched.inc index e935993aa0..d6f1c67087 100644 --- a/kernel/branches/Kolibri-acpi/core/sched.inc +++ b/kernel/branches/Kolibri-acpi/core/sched.inc @@ -16,7 +16,8 @@ $Revision$ align 32 irq0: pushad - Mov ds, ax, app_data + mov ax, app_data + mov ds, ax mov es, ax inc [timer_ticks] mov eax, [timer_ticks] @@ -101,8 +102,10 @@ do_change_task: mov [esi+APPDATA.saved_esp], esp mov esp, [ebx+APPDATA.saved_esp] ; set new thread io-map - Mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)],eax,[ebx+APPDATA.io_map] - Mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)],eax,[ebx+APPDATA.io_map+4] + mov eax, [ebx+APPDATA.io_map] + mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)], eax + mov eax, [ebx+APPDATA.io_map+4] + mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], eax ; set new thread memory-map mov eax, [ebx+APPDATA.process] cmp eax, [current_process] @@ -113,7 +116,8 @@ do_change_task: @@: ; set tss.esp0 - Mov [tss._esp0],eax,[ebx+APPDATA.saved_esp0] + mov eax, [ebx+APPDATA.saved_esp0] + mov [tss._esp0], eax mov edx, [ebx+APPDATA.tls_base] @@ -126,7 +130,8 @@ do_change_task: mov fs, dx ; set gs selector unconditionally - Mov gs,ax,graph_data + Mov ax, graph_data + Mov gs, ax ; set CR0.TS cmp bh, byte[fpu_owner] ;bh == incoming task (new) clts ;clear a task switch flag @@ -280,7 +285,7 @@ proc find_next_task call [ebx+APPDATA.wait_test] mov [esp+28], eax popad - or eax, eax + test eax, eax jnz @f ; testing for timeout mov eax, [timer_ticks] diff --git a/kernel/branches/Kolibri-acpi/core/sync.inc b/kernel/branches/Kolibri-acpi/core/sync.inc index cb87a2a923..9d2ec259b3 100644 --- a/kernel/branches/Kolibri-acpi/core/sync.inc +++ b/kernel/branches/Kolibri-acpi/core/sync.inc @@ -86,12 +86,12 @@ f77: cmp ecx, (PROC.pdt_0 - PROC.htab)/4 jae .fail - mov esi, [current_process] - mov edi, [esi+PROC.htab+ecx*4] + mov edi, [current_process] + mov ebp, [edi+PROC.htab+ecx*4] - cmp [edi+FUTEX.magic], 'FUTX' + cmp [ebp+FUTEX.magic], 'FUTX' jne .fail - cmp [edi+FUTEX.handle], ecx + cmp [ebp+FUTEX.handle], ecx jne .fail jmp dword [f77call+ebx*4] @@ -113,21 +113,24 @@ align 4 align 4 ;ecx futex handle -;esi current process -;edi futex object +;edi current process +;ebp futex object .futex_destroy: - mov ecx, edi + mov ecx, ebp call destroy_futex mov [esp+SYSCALL_STACK._eax], eax ret align 4 ;ecx futex handle -;esi current process -;edi futex object ;edx control value +;esi timeout +;edi current process +;ebp futex object .futex_wait: - mov ecx, [edi+FUTEX.pointer] + test esi, esi + jnz .futex_wait_timeout + mov ecx, [ebp+FUTEX.pointer] mov eax, edx lock cmpxchg [ecx], edx ;wait until old_value == new_value jz .wait_slow @@ -143,7 +146,7 @@ align 4 mov ebx, [TASK_BASE] mov [ebx+TASKDATA.state], 1 mov [esp+MUTEX_WAITER.task], ebx - lea esi, [edi+FUTEX.wait_list] + lea esi, [ebp+FUTEX.wait_list] list_add_tail esp, esi ;esp= new waiter, esi= list head @@ -160,6 +163,72 @@ align 4 mov [esp+SYSCALL_STACK._eax], 0 ret +align 4 +;ecx futex handle +;edx control value +;esi timeout +;edi current process +;ebp futex object + +.futex_wait_timeout: + mov ecx, [ebp+FUTEX.pointer] + mov eax, edx + lock cmpxchg [ecx], edx ;wait until old_value == new_value + jz .wait_slow_timeout + + mov [esp+SYSCALL_STACK._eax], 0 + ret + +align 4 +.wait_test: + xor eax, eax + ret + +.wait_slow_timeout: + pushfd + cli + + sub esp, sizeof.MUTEX_WAITER + + mov ebx, [current_slot] + mov [ebx+APPDATA.wait_test], f77.wait_test + mov [ebx+APPDATA.wait_timeout], esi + mov [ebx+APPDATA.wait_param], ebp + mov eax, [timer_ticks] + mov [ebx+APPDATA.wait_begin], eax + mov eax, [TASK_BASE] + mov [eax+TASKDATA.state], 5 + + mov [esp+MUTEX_WAITER.task], ebx + lea esi, [ebp+FUTEX.wait_list] + + list_add_tail esp, esi ;esp= new waiter, esi= list head + +.again_timeout: + call change_task + mov eax, [ebx+APPDATA.wait_param] + test eax, eax + jz .timeout + + lock cmpxchg [ecx], edx + jz .again_timeout +@@: + list_del esp + add esp, sizeof.MUTEX_WAITER + + popfd + mov [esp+SYSCALL_STACK._eax], 0 + ret + +.timeout: + list_del esp + add esp, sizeof.MUTEX_WAITER + + popfd + mov [esp+SYSCALL_STACK._eax], -1 + ret + + align 4 ;ecx futex handle ;esi current process diff --git a/kernel/branches/Kolibri-acpi/gui/event.inc b/kernel/branches/Kolibri-acpi/gui/event.inc index 3f05bd7135..bf40405226 100644 --- a/kernel/branches/Kolibri-acpi/gui/event.inc +++ b/kernel/branches/Kolibri-acpi/gui/event.inc @@ -104,7 +104,8 @@ align 4 mov [eax+EVENT.state], ecx mov [eax+EVENT.pid], edx inc [event_uid] - Mov [eax+EVENT.id],edx,[event_uid] + mov edx, [event_uid] + mov [eax+EVENT.id], edx or esi, esi jz RemoveEventTo lea edi, [eax+EVENT.code] @@ -277,7 +278,8 @@ Wait_events_ex: jnz @f ;RET mov [esi+APPDATA.wait_test], edx mov [esi+APPDATA.wait_timeout], ebx - Mov [esi+APPDATA.wait_begin],eax,[timer_ticks] + mov eax, [timer_ticks] + mov [esi+APPDATA.wait_begin], eax mov eax, [TASK_BASE] mov [eax+TASKDATA.state], 5 call change_task diff --git a/kernel/branches/Kolibri-acpi/macros.inc b/kernel/branches/Kolibri-acpi/macros.inc index 7062230069..f2ef5cf627 100644 --- a/kernel/branches/Kolibri-acpi/macros.inc +++ b/kernel/branches/Kolibri-acpi/macros.inc @@ -83,11 +83,6 @@ end if } ; \end{diamond}[29.09.2006] -macro Mov op1,op2,op3 ; op1 = op2 = op3 - { - mov op2, op3 - mov op1, op2 - } macro list_init head {