- SHORTLOCK( &glThreadListLock );
-
- // - Remove from active list
- us = Threads_RemActive();
- us->Next = NULL;
- // - Mark as sleeping
- us->Status = THREAD_STAT_RWLOCKSLEEP;
- us->WaitPointer = Lock;
-
- // - Add to waiting
- if(Lock->ReaderWaiting)
- Lock->ReaderWaitingLast->Next = us;
- else
- Lock->ReaderWaiting = us;
- Lock->ReaderWaitingLast = us;
-
- #if DEBUG_TRACE_STATE
- Log("%p (%i %s) waiting on rwlock %p",
- us, us->TID, us->ThreadName, Lock);
- #endif
-
- SHORTREL( &glThreadListLock );
- SHORTREL( &Lock->Protector );
- while(us->Status == THREAD_STAT_RWLOCKSLEEP) Threads_Yield();
- // We're only woken when we get the lock
- // TODO: Handle when this isn't the case
- us->WaitPointer = NULL;
+ Threads_int_Sleep(THREAD_STAT_RWLOCKSLEEP, Lock, 0,
+ &Lock->ReaderWaiting, &Lock->ReaderWaitingLast,
+ &Lock->Protector);