コード例 #1
0
ファイル: rw_lock.cpp プロジェクト: mmanley/Antares
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;
}
コード例 #2
0
ファイル: pthread.cpp プロジェクト: looncraz/haiku
pthread_t
pthread_self(void)
{
	pthread_thread* thread = get_user_thread()->pthread;
	if (thread == NULL)
		return &sMainThread;

	return thread;
}