Subversion Repositories HelenOS

Rev

Rev 2071 | Rev 2089 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2071 Rev 2087
Line 218... Line 218...
218
             * The sleep timed out.
218
             * The sleep timed out.
219
             * We just restore interrupt priority level.
219
             * We just restore interrupt priority level.
220
             */
220
             */
221
        case ESYNCH_OK_BLOCKED:    
221
        case ESYNCH_OK_BLOCKED:    
222
            /*
222
            /*
223
             * We were woken with rwl->readers_in already incremented.
223
             * We were woken with rwl->readers_in already
-
 
224
             * incremented.
-
 
225
             *
224
             * Note that this arrangement avoids race condition between
226
             * Note that this arrangement avoids race condition
225
             * two concurrent readers. (Race is avoided if 'exclusive' is
227
             * between two concurrent readers. (Race is avoided if
226
             * locked at the same time as 'readers_in' is incremented.
228
             * 'exclusive' is locked at the same time as
227
             * Same time means both events happen atomically when
229
             * 'readers_in' is incremented. Same time means both
228
             * rwl->lock is held.)
230
             * events happen atomically when rwl->lock is held.)
229
             */
231
             */
230
            interrupts_restore(ipl);
232
            interrupts_restore(ipl);
231
            break;
233
            break;
232
        case ESYNCH_OK_ATOMIC:
234
        case ESYNCH_OK_ATOMIC:
233
            panic("_mutex_lock_timeout()==ESYNCH_OK_ATOMIC\n");
235
            panic("_mutex_lock_timeout()==ESYNCH_OK_ATOMIC\n");
Line 321... Line 323...
321
    bool one_more = true;
323
    bool one_more = true;
322
   
324
   
323
    spinlock_lock(&rwl->exclusive.sem.wq.lock);
325
    spinlock_lock(&rwl->exclusive.sem.wq.lock);
324
 
326
 
325
    if (!list_empty(&rwl->exclusive.sem.wq.head))
327
    if (!list_empty(&rwl->exclusive.sem.wq.head))
326
        t = list_get_instance(rwl->exclusive.sem.wq.head.next, thread_t, wq_link);
328
        t = list_get_instance(rwl->exclusive.sem.wq.head.next, thread_t,
-
 
329
            wq_link);
327
    do {
330
    do {
328
        if (t) {
331
        if (t) {
329
            spinlock_lock(&t->lock);
332
            spinlock_lock(&t->lock);
330
            type = t->rwlock_holder_type;
333
            type = t->rwlock_holder_type;
331
            spinlock_unlock(&t->lock);         
334
            spinlock_unlock(&t->lock);         
Line 341... Line 344...
341
 
344
 
342
 
345
 
343
        if (type == RWLOCK_READER) {
346
        if (type == RWLOCK_READER) {
344
            /*
347
            /*
345
             * Waking up a reader.
348
             * Waking up a reader.
346
             * We are responsible for incrementing rwl->readers_in for it.
349
             * We are responsible for incrementing rwl->readers_in
-
 
350
             * for it.
347
             */
351
             */
348
             rwl->readers_in++;
352
             rwl->readers_in++;
349
        }
353
        }
350
 
354
 
351
        /*
355
        /*
Line 358... Line 362...
358
         */
362
         */
359
        _waitq_wakeup_unsafe(&rwl->exclusive.sem.wq, WAKEUP_FIRST);
363
        _waitq_wakeup_unsafe(&rwl->exclusive.sem.wq, WAKEUP_FIRST);
360
       
364
       
361
        t = NULL;
365
        t = NULL;
362
        if (!list_empty(&rwl->exclusive.sem.wq.head)) {
366
        if (!list_empty(&rwl->exclusive.sem.wq.head)) {
363
            t = list_get_instance(rwl->exclusive.sem.wq.head.next, thread_t, wq_link);
367
            t = list_get_instance(rwl->exclusive.sem.wq.head.next,
-
 
368
                thread_t, wq_link);
364
            if (t) {
369
            if (t) {
365
                spinlock_lock(&t->lock);
370
                spinlock_lock(&t->lock);
366
                if (t->rwlock_holder_type != RWLOCK_READER)
371
                if (t->rwlock_holder_type != RWLOCK_READER)
367
                    one_more = false;
372
                    one_more = false;
368
                spinlock_unlock(&t->lock); 
373
                spinlock_unlock(&t->lock);