Subversion Repositories Kolibri OS

Rev

Rev 5130 | Rev 5344 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5130 Rev 5343
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 5130 $
8
$Revision: 5343 $
9
 
9
 
10
 
10
 
Line 157... Line 157...
157
 
157
 
158
 
158
 
159
struct  MUTEX_WAITER
159
struct  MUTEX_WAITER
-
 
160
        list    LHEAD
160
        list    LHEAD
161
        task    dd ?
Line 161... Line 162...
161
        task    dd ?
162
        type    dd ?
Line 162... Line 163...
162
ends
163
ends
163
 
164
 
164
;void  __fastcall mutex_init(struct mutex *lock)
165
;void  __fastcall mutex_init(struct mutex *lock)
165
 
166
 
166
align 4
167
align 4
167
mutex_init:
168
mutex_init:
Line 168... Line -...
168
        mov     [ecx+MUTEX.lhead.next], ecx
-
 
169
        mov     [ecx+MUTEX.lhead.prev], ecx
169
        mov     [ecx+MUTEX.wait_list.next], ecx
Line 170... Line 170...
170
        mov     [ecx+MUTEX.count], 1
170
        mov     [ecx+MUTEX.wait_list.prev], ecx
171
        ret
171
        mov     [ecx+MUTEX.count], 1
Line 198... Line 198...
198
 
198
 
199
        mov     [edx+TASKDATA.state], 1
199
        mov     [edx+TASKDATA.state], 1
200
        call    change_task
200
        call    change_task
201
        jmp     .forever
201
        jmp     .forever
202
@@:
202
@@:
203
        mov     edx, [esp+MUTEX_WAITER.list.next]
203
        mov     eax, ecx
Line 204... Line -...
204
        mov     eax, [esp+MUTEX_WAITER.list.prev]
-
 
205
 
-
 
206
        mov     [eax+MUTEX_WAITER.list.next], edx
204
        list_del esp
207
        mov     [edx+MUTEX_WAITER.list.prev], eax
205
 
Line 208... Line 206...
208
        cmp     [ecx+MUTEX.lhead.next], ecx
206
        cmp     [eax+MUTEX.wait_list.next], eax
209
        jne     @F
207
        jne     @F
210
 
208
 
Line 211... Line 209...
211
        mov     [ecx+MUTEX.count], 0
209
        mov     [eax+MUTEX.count], 0
212
@@:
210
@@:
Line 222... Line 220...
222
mutex_unlock:
220
mutex_unlock:
Line 223... Line 221...
223
 
221
 
224
        pushfd
222
        pushfd
Line 225... Line 223...
225
        cli
223
        cli
226
 
224
 
227
        mov     eax, [ecx+MUTEX.lhead.next]
225
        mov     eax, [ecx+MUTEX.wait_list.next]
228
        cmp     eax, ecx
226
        cmp     eax, ecx
Line 229... Line 227...
229
        mov     [ecx+MUTEX.count], 1
227
        mov     [ecx+MUTEX.count], 1
Line 234... Line 232...
234
@@:
232
@@:
235
        popfd
233
        popfd
236
        ret
234
        ret
Line -... Line 235...
-
 
235
 
-
 
236
 
-
 
237
;void __fastcall down_read(struct rw_semaphore *sem)
-
 
238
 
-
 
239
align 4
-
 
240
down_read:
-
 
241
        pushfd
-
 
242
        cli
-
 
243
 
-
 
244
        mov     eax, [ecx+RWSEM.count]
-
 
245
        test    eax, eax
-
 
246
        js      @F
-
 
247
 
-
 
248
        cmp     ecx, [ecx+RWSEM.wait_list.next]
-
 
249
        je      .ok
-
 
250
@@:
-
 
251
        sub     esp, sizeof.MUTEX_WAITER
-
 
252
 
-
 
253
        mov     eax, [TASK_BASE]
-
 
254
        mov     [esp+MUTEX_WAITER.task], eax
-
 
255
        mov     [esp+MUTEX_WAITER.type], 1; RWSEM_WAITING_FOR_READ
-
 
256
        mov     [eax+TASKDATA.state], 1
-
 
257
 
-
 
258
        list_add_tail esp, ecx      ;esp= new waiter, ecx= list head
-
 
259
 
-
 
260
        call    change_task
-
 
261
 
-
 
262
        add     esp, sizeof.MUTEX_WAITER
-
 
263
        popfd
-
 
264
        ret
-
 
265
.ok:
-
 
266
        inc     eax
-
 
267
        mov     [ecx+RWSEM.count], eax
-
 
268
 
-
 
269
        popfd
-
 
270
        ret
-
 
271
 
-
 
272
;void __fastcall down_write(struct rw_semaphore *sem)
-
 
273
 
-
 
274
align 4
-
 
275
down_write:
-
 
276
        pushfd
-
 
277
        cli
-
 
278
        sub     esp, sizeof.MUTEX_WAITER
-
 
279
 
-
 
280
        mov     edx, [TASK_BASE]
-
 
281
        mov     [esp+MUTEX_WAITER.task], edx
-
 
282
        mov     [esp+MUTEX_WAITER.type], 2; RWSEM_WAITING_FOR_WRITE
-
 
283
        mov     [edx+TASKDATA.state], 1
-
 
284
 
-
 
285
        list_add_tail esp, ecx      ;esp= new waiter, ecx= list head
-
 
286
 
-
 
287
        xor     eax, eax
-
 
288
        not     eax
-
 
289
 
-
 
290
.forever:
-
 
291
        test    eax, [ecx+RWSEM.count]
-
 
292
        jz      @F
-
 
293
 
-
 
294
        mov     [edx+TASKDATA.state], 1
-
 
295
        call    change_task
-
 
296
        jmp     .forever
-
 
297
@@:
-
 
298
        mov     [ecx+RWSEM.count], eax
-
 
299
        list_del esp
-
 
300
 
-
 
301
        add     esp, sizeof.MUTEX_WAITER
-
 
302
        popfd
237
 
303
        ret
Line 238... Line 304...
238
 
304
 
239
purge MUTEX_WAITER
305
purge MUTEX_WAITER
240
 
306