/** * Gets the next waiter index. The index is zero for the first waiter. * If waiter was not the first, the index if the highest active index + 1. * The highest active index is determined by checking the last entries * in both exclusive and shared lists. Must be called under synchronization */ STATIC int RWLOCK_GetNextWaiterIndex(RWLock * lock) { int i = 0; RWLockWaiter * lastWaiter; QEntry * e = QUEUE_Last(&lock->shareWaiters); if (e) { lastWaiter = QCAST(e,RWLockWaiter,entry); i = lastWaiter->index + 1; } e = QUEUE_Last(&lock->exclusiveWaiters); if (e) { lastWaiter = QCAST(e,RWLockWaiter,entry); i = MAX(i,lastWaiter->index + 1); } return i; }
/** * Removes the last entry from the queue. * Returns NULL if queue is empty */ QEntry * QUEUE_RemoveTail(Queue * q) { QEntry * e = QUEUE_Last(q); if (e) { _RemoveEntry(e); _InvalidateEntry(e); q->size--; } return e; }