2009-09-17 13:55:38 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; Synhronization for MenuetOS. ;;
|
|
|
|
;; Author: Halyavin Andrey, halyavin@land.ru ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2009-10-12 16:39:59 +02:00
|
|
|
$Revision$
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ~defined sync_inc
|
|
|
|
sync_inc_fix:
|
|
|
|
sync_inc fix sync_inc_fix
|
|
|
|
|
|
|
|
;simplest mutex.
|
|
|
|
macro SimpleMutex name
|
|
|
|
{
|
|
|
|
; iglobal
|
|
|
|
name dd 0
|
|
|
|
name#.type = 1
|
|
|
|
; endg
|
|
|
|
}
|
|
|
|
macro WaitSimpleMutex name
|
|
|
|
{
|
|
|
|
local start_wait,ok
|
|
|
|
start_wait=$
|
2012-02-22 17:06:05 +01:00
|
|
|
cli
|
|
|
|
cmp [name], dword 0
|
|
|
|
jz ok
|
|
|
|
sti
|
|
|
|
call change_task
|
|
|
|
jmp start_wait
|
2009-09-17 13:55:38 +02:00
|
|
|
ok=$
|
2012-02-22 17:06:05 +01:00
|
|
|
push eax
|
|
|
|
mov eax, dword [TASK_BASE+second_base_address]
|
|
|
|
mov eax, [eax+TASKDATA.pid]
|
|
|
|
mov [name], eax
|
|
|
|
pop eax
|
|
|
|
sti
|
2009-09-17 13:55:38 +02:00
|
|
|
}
|
|
|
|
macro ReleaseSimpleMutex name
|
|
|
|
{
|
2012-02-22 17:06:05 +01:00
|
|
|
mov [name], dword 0
|
2009-09-17 13:55:38 +02:00
|
|
|
}
|
|
|
|
macro TryWaitSimpleMutex name ;result in eax and in flags
|
|
|
|
{
|
|
|
|
local ok,try_end
|
2012-02-22 17:06:05 +01:00
|
|
|
cmp [name], dword 0
|
|
|
|
jz ok
|
|
|
|
xor eax, eax
|
|
|
|
jmp try_end
|
2009-09-17 13:55:38 +02:00
|
|
|
ok=$
|
2012-02-22 17:06:05 +01:00
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
2009-09-17 13:55:38 +02:00
|
|
|
try_end=$
|
|
|
|
}
|
|
|
|
macro SimpleCriticalSection name
|
|
|
|
{
|
|
|
|
; iglobal
|
|
|
|
name dd 0
|
|
|
|
dd 0
|
|
|
|
name#.type=2
|
|
|
|
; endg
|
|
|
|
}
|
|
|
|
macro WaitSimpleCriticalSection name
|
|
|
|
{
|
|
|
|
local start_wait,first_wait,inc_counter,end_wait
|
2012-02-22 17:06:05 +01:00
|
|
|
push eax
|
|
|
|
mov eax, [TASK_BASE+second_base_address]
|
|
|
|
mov eax, [eax+TASKDATA.pid]
|
2009-09-17 13:55:38 +02:00
|
|
|
start_wait=$
|
2012-02-22 17:06:05 +01:00
|
|
|
cli
|
|
|
|
cmp [name], dword 0
|
|
|
|
jz first_wait
|
|
|
|
cmp [name], eax
|
|
|
|
jz inc_counter
|
|
|
|
sti
|
|
|
|
call change_task
|
|
|
|
jmp start_wait
|
2009-09-17 13:55:38 +02:00
|
|
|
first_wait=$
|
2012-02-22 17:06:05 +01:00
|
|
|
mov [name], eax
|
|
|
|
mov [name+4], dword 1
|
|
|
|
jmp end_wait
|
2009-09-17 13:55:38 +02:00
|
|
|
inc_counter=$
|
2012-02-22 17:06:05 +01:00
|
|
|
inc dword [name+4]
|
2009-09-17 13:55:38 +02:00
|
|
|
end_wait=$
|
2012-02-22 17:06:05 +01:00
|
|
|
sti
|
|
|
|
pop eax
|
2009-09-17 13:55:38 +02:00
|
|
|
}
|
|
|
|
macro ReleaseSimpleCriticalSection name
|
|
|
|
{
|
|
|
|
local release_end
|
2012-02-22 17:06:05 +01:00
|
|
|
dec dword [name+4]
|
|
|
|
jnz release_end
|
|
|
|
mov [name], dword 0
|
2009-09-17 13:55:38 +02:00
|
|
|
release_end=$
|
|
|
|
}
|
|
|
|
macro TryWaitSimpleCriticalSection name ;result in eax and in flags
|
|
|
|
{
|
|
|
|
local ok,try_end
|
2012-02-22 17:06:05 +01:00
|
|
|
mov eax, [CURRENT_TASK+second_base_address]
|
|
|
|
mov eax, [eax+TASKDATA.pid]
|
|
|
|
cmp [name], eax
|
|
|
|
jz ok
|
|
|
|
cmp [name], 0
|
|
|
|
jz ok
|
|
|
|
xor eax, eax
|
|
|
|
jmp try_end
|
2009-09-17 13:55:38 +02:00
|
|
|
ok=$
|
2012-02-22 17:06:05 +01:00
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
2009-09-17 13:55:38 +02:00
|
|
|
try_end=$
|
|
|
|
}
|
|
|
|
_cli equ call MEM_HeapLock
|
|
|
|
_sti equ call MEM_HeapUnLock
|
|
|
|
end if
|
|
|
|
|