Rev 5597 | Rev 5605 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5597 | Rev 5599 | ||
---|---|---|---|
Line 5... | Line 5... | ||
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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 9... | Line 9... | ||
9 | 9 | ||
Line 10... | Line 10... | ||
10 | $Revision: 5597 $ |
10 | $Revision: 5599 $ |
11 | 11 | ||
12 | align 4 |
12 | align 4 |
13 | ;struct futex* __fastcall create_futex(int *ptr) |
13 | ;struct futex* __fastcall create_futex(int *ptr) |
Line 84... | Line 84... | ||
84 | cmp ecx, STDERR_FILENO |
84 | cmp ecx, STDERR_FILENO |
85 | jbe .fail |
85 | jbe .fail |
86 | cmp ecx, (PROC.pdt_0 - PROC.htab)/4 |
86 | cmp ecx, (PROC.pdt_0 - PROC.htab)/4 |
87 | jae .fail |
87 | jae .fail |
Line 88... | Line 88... | ||
88 | 88 | ||
89 | mov esi, [current_process] |
89 | mov edi, [current_process] |
Line 90... | Line 90... | ||
90 | mov edi, [esi+PROC.htab+ecx*4] |
90 | mov ebp, [edi+PROC.htab+ecx*4] |
91 | 91 | ||
92 | cmp [edi+FUTEX.magic], 'FUTX' |
92 | cmp [ebp+FUTEX.magic], 'FUTX' |
93 | jne .fail |
93 | jne .fail |
Line 94... | Line 94... | ||
94 | cmp [edi+FUTEX.handle], ecx |
94 | cmp [ebp+FUTEX.handle], ecx |
Line 95... | Line 95... | ||
95 | jne .fail |
95 | jne .fail |
Line 111... | Line 111... | ||
111 | ret |
111 | ret |
Line 112... | Line 112... | ||
112 | 112 | ||
113 | 113 | ||
114 | align 4 |
114 | align 4 |
115 | ;ecx futex handle |
115 | ;ecx futex handle |
116 | ;esi current process |
116 | ;edi current process |
117 | ;edi futex object |
117 | ;ebp futex object |
118 | .futex_destroy: |
118 | .futex_destroy: |
119 | mov ecx, edi |
119 | mov ecx, ebp |
120 | call destroy_futex |
120 | call destroy_futex |
Line 121... | Line 121... | ||
121 | mov [esp+SYSCALL_STACK._eax], eax |
121 | mov [esp+SYSCALL_STACK._eax], eax |
122 | ret |
122 | ret |
123 | - | ||
124 | align 4 |
- | |
125 | ;ecx futex handle |
123 | |
- | 124 | align 4 |
|
- | 125 | ;ecx futex handle |
|
- | 126 | ;edx control value |
|
126 | ;esi current process |
127 | ;esi timeout |
- | 128 | ;edi current process |
|
- | 129 | ;ebp futex object |
|
127 | ;edi futex object |
130 | .futex_wait: |
128 | ;edx control value |
131 | test esi, esi |
129 | .futex_wait: |
132 | jnz .futex_wait_timeout |
130 | mov ecx, [edi+FUTEX.pointer] |
133 | mov ecx, [ebp+FUTEX.pointer] |
Line 131... | Line 134... | ||
131 | mov eax, edx |
134 | mov eax, edx |
Line 141... | Line 144... | ||
141 | 144 | ||
142 | sub esp, sizeof.MUTEX_WAITER |
145 | sub esp, sizeof.MUTEX_WAITER |
143 | mov ebx, [TASK_BASE] |
146 | mov ebx, [TASK_BASE] |
144 | mov [ebx+TASKDATA.state], 1 |
147 | mov [ebx+TASKDATA.state], 1 |
145 | mov [esp+MUTEX_WAITER.task], ebx |
148 | mov [esp+MUTEX_WAITER.task], ebx |
Line 146... | Line 149... | ||
146 | lea esi, [edi+FUTEX.wait_list] |
149 | lea esi, [ebp+FUTEX.wait_list] |
Line 147... | Line 150... | ||
147 | 150 | ||
148 | list_add_tail esp, esi ;esp= new waiter, esi= list head |
151 | list_add_tail esp, esi ;esp= new waiter, esi= list head |
Line 160... | Line 163... | ||
160 | mov [esp+SYSCALL_STACK._eax], 0 |
163 | mov [esp+SYSCALL_STACK._eax], 0 |
161 | ret |
164 | ret |
Line 162... | Line 165... | ||
162 | 165 | ||
163 | align 4 |
166 | align 4 |
- | 167 | ;ecx futex handle |
|
- | 168 | ;edx control value |
|
- | 169 | ;esi timeout |
|
- | 170 | ;edi current process |
|
- | 171 | ;ebp futex object |
|
- | 172 | ||
- | 173 | .futex_wait_timeout: |
|
- | 174 | mov ecx, [ebp+FUTEX.pointer] |
|
- | 175 | mov eax, edx |
|
- | 176 | lock cmpxchg [ecx], edx ;wait until old_value == new_value |
|
- | 177 | jz .wait_slow_timeout |
|
- | 178 | ||
- | 179 | mov [esp+SYSCALL_STACK._eax], 0 |
|
- | 180 | ret |
|
- | 181 | ||
- | 182 | align 4 |
|
- | 183 | .wait_test: |
|
- | 184 | xor eax, eax |
|
- | 185 | ret |
|
- | 186 | ||
- | 187 | .wait_slow_timeout: |
|
- | 188 | pushfd |
|
- | 189 | cli |
|
- | 190 | ||
- | 191 | sub esp, sizeof.MUTEX_WAITER |
|
- | 192 | ||
- | 193 | mov ebx, [current_slot] |
|
- | 194 | mov [ebx+APPDATA.wait_test], f77.wait_test |
|
- | 195 | mov [ebx+APPDATA.wait_timeout], esi |
|
- | 196 | mov [ebx+APPDATA.wait_param], ebp |
|
- | 197 | mov eax, [timer_ticks] |
|
- | 198 | mov [ebx+APPDATA.wait_begin], eax |
|
- | 199 | mov eax, [TASK_BASE] |
|
- | 200 | mov [eax+TASKDATA.state], 5 |
|
- | 201 | ||
- | 202 | mov [esp+MUTEX_WAITER.task], ebx |
|
- | 203 | lea esi, [ebp+FUTEX.wait_list] |
|
- | 204 | ||
- | 205 | list_add_tail esp, esi ;esp= new waiter, esi= list head |
|
- | 206 | ||
- | 207 | .again_timeout: |
|
- | 208 | call change_task |
|
- | 209 | mov eax, [ebx+APPDATA.wait_param] |
|
- | 210 | test eax, eax |
|
- | 211 | jz .timeout |
|
- | 212 | ||
- | 213 | lock cmpxchg [ecx], edx |
|
- | 214 | jz .again_timeout |
|
- | 215 | @@: |
|
- | 216 | list_del esp |
|
- | 217 | add esp, sizeof.MUTEX_WAITER |
|
- | 218 | ||
- | 219 | popfd |
|
- | 220 | mov [esp+SYSCALL_STACK._eax], 0 |
|
- | 221 | ret |
|
- | 222 | ||
- | 223 | .timeout: |
|
- | 224 | list_del esp |
|
- | 225 | add esp, sizeof.MUTEX_WAITER |
|
- | 226 | ||
- | 227 | popfd |
|
- | 228 | mov [esp+SYSCALL_STACK._eax], -1 |
|
- | 229 | ret |
|
- | 230 | ||
- | 231 | ||
- | 232 | align 4 |
|
164 | ;ecx futex handle |
233 | ;ecx futex handle |
165 | ;esi current process |
234 | ;esi current process |
166 | ;edi futex object |
235 | ;edi futex object |
167 | ;edx threads count |
236 | ;edx threads count |