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