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