Subversion Repositories Kolibri OS

Rev

Rev 2434 | Rev 5565 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2465 Serge 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;; Synhronization for MenuetOS.                                 ;;
7
;; Author: Halyavin Andrey, halyavin@land.ru                    ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
 
593 mikedld 10
$Revision: 2465 $
11
 
12
 
1 ha 13
if ~defined sync_inc
14
sync_inc_fix:
15
sync_inc fix sync_inc_fix
16
 
17
;simplest mutex.
18
macro SimpleMutex name
19
{
20
;  iglobal
21
    name dd 0
22
    name#.type = 1
23
;  endg
24
}
25
macro WaitSimpleMutex name
26
{
27
  local start_wait,ok
379 serge 28
start_wait=$
2434 Serge 29
        cli
30
        cmp     [name], dword 0
31
        jz      ok
32
        sti
33
        call    change_task
34
        jmp     start_wait
1 ha 35
ok=$
2434 Serge 36
        push    eax
37
        mov     eax, dword [TASK_BASE+second_base_address]
38
        mov     eax, [eax+TASKDATA.pid]
39
        mov     [name], eax
40
        pop     eax
41
        sti
1 ha 42
}
43
macro ReleaseSimpleMutex name
44
{
2434 Serge 45
        mov     [name], dword 0
1 ha 46
}
47
macro TryWaitSimpleMutex name  ;result in eax and in flags
48
{
49
  local ok,try_end
2434 Serge 50
        cmp     [name], dword 0
51
        jz      ok
52
        xor     eax, eax
53
        jmp     try_end
1 ha 54
ok=$
2434 Serge 55
        xor     eax, eax
56
        inc     eax
1 ha 57
try_end=$
58
}
59
macro SimpleCriticalSection name
60
{
61
;  iglobal
62
    name  dd 0
63
          dd 0
64
    name#.type=2
65
;  endg
66
}
67
macro WaitSimpleCriticalSection name
68
{
69
  local start_wait,first_wait,inc_counter,end_wait
2434 Serge 70
        push    eax
71
        mov     eax, [TASK_BASE+second_base_address]
72
        mov     eax, [eax+TASKDATA.pid]
1 ha 73
start_wait=$
2434 Serge 74
        cli
75
        cmp     [name], dword 0
76
        jz      first_wait
77
        cmp     [name], eax
78
        jz      inc_counter
79
        sti
80
        call    change_task
81
        jmp     start_wait
1 ha 82
first_wait=$
2434 Serge 83
        mov     [name], eax
84
        mov     [name+4], dword 1
85
        jmp     end_wait
1 ha 86
inc_counter=$
2434 Serge 87
        inc     dword [name+4]
1 ha 88
end_wait=$
2434 Serge 89
        sti
90
        pop     eax
1 ha 91
}
92
macro ReleaseSimpleCriticalSection name
93
{
94
  local release_end
2434 Serge 95
        dec     dword [name+4]
96
        jnz     release_end
97
        mov     [name], dword 0
1 ha 98
release_end=$
99
}
100
macro TryWaitSimpleCriticalSection name ;result in eax and in flags
101
{
102
  local ok,try_end
2434 Serge 103
        mov     eax, [CURRENT_TASK+second_base_address]
104
        mov     eax, [eax+TASKDATA.pid]
105
        cmp     [name], eax
106
        jz      ok
107
        cmp     [name], 0
108
        jz      ok
109
        xor     eax, eax
110
        jmp     try_end
1 ha 111
ok=$
2434 Serge 112
        xor     eax, eax
113
        inc     eax
1 ha 114
try_end=$
115
}
116
_cli equ call MEM_HeapLock
117
_sti equ call MEM_HeapUnLock
118
end if
119