static status_t rw_lock_wait(rw_lock *lock, bool writer) { rw_lock_waiter waiter; waiter.thread = find_thread(NULL); waiter.next = NULL; waiter.writer = writer; if (lock->waiters != NULL) lock->last_waiter->next = &waiter; else lock->waiters = &waiter; lock->last_waiter = &waiter; // the rw_lock is locked when entering, release it before blocking get_user_thread()->wait_status = 1; mutex_unlock(&lock->lock); status_t result; do { result = _kern_block_thread(0, 0); } while (result == B_INTERRUPTED); // and lock it again before returning mutex_lock(&lock->lock); return result; }
pthread_t pthread_self(void) { pthread_thread* thread = get_user_thread()->pthread; if (thread == NULL) return &sMainThread; return thread; }