Update to match changed pthread__park() interface.

This commit is contained in:
ad 2007-03-05 23:56:17 +00:00
parent fe47a5c777
commit c79299e2ec
3 changed files with 38 additions and 19 deletions

View File

@ -1,11 +1,11 @@
/* $NetBSD: pthread_barrier.c,v 1.10 2007/03/02 18:53:52 ad Exp $ */
/* $NetBSD: pthread_barrier.c,v 1.11 2007/03/05 23:56:17 ad Exp $ */
/*-
* Copyright (c) 2001, 2003, 2006, 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Nathan J. Williams, and by Jason R. Thorpe.
* by Nathan J. Williams, by Jason R. Thorpe, and by Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread_barrier.c,v 1.10 2007/03/02 18:53:52 ad Exp $");
__RCSID("$NetBSD: pthread_barrier.c,v 1.11 2007/03/05 23:56:17 ad Exp $");
#include <errno.h>
@ -167,7 +167,7 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
self, barrier));
barrier->ptb_generation++;
pthread__unpark_all(self, &barrier->ptb_lock, barrier,
pthread__unpark_all(self, &barrier->ptb_lock,
&barrier->ptb_waiters);
return PTHREAD_BARRIER_SERIAL_THREAD;
}
@ -177,8 +177,11 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
while (gen == barrier->ptb_generation) {
SDPRINTF(("(barrier wait %p) Waiting on %p\n",
self, barrier));
(void)pthread__park(self, &barrier->ptb_lock, barrier,
&barrier->ptb_waiters, NULL, 1, 0);
PTQ_INSERT_TAIL(&barrier->ptb_waiters, self, pt_sleep);
self->pt_sleeponq = 1;
self->pt_sleepobj = &barrier->ptb_waiters;
(void)pthread__park(self, &barrier->ptb_lock,
&barrier->ptb_waiters, NULL, 0);
SDPRINTF(("(barrier wait %p) Woke up on %p\n",
self, barrier));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread_mutex.c,v 1.25 2007/03/02 18:53:52 ad Exp $ */
/* $NetBSD: pthread_mutex.c,v 1.26 2007/03/05 23:56:18 ad Exp $ */
/*-
* Copyright (c) 2001, 2003, 2006, 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread_mutex.c,v 1.25 2007/03/02 18:53:52 ad Exp $");
__RCSID("$NetBSD: pthread_mutex.c,v 1.26 2007/03/05 23:56:18 ad Exp $");
#include <errno.h>
#include <limits.h>
@ -267,8 +267,10 @@ pthread_mutex_lock_slow(pthread_mutex_t *mutex)
* but it's okay since we're just going to
* retry.
*/
self->pt_sleeponq = 1;
self->pt_sleepobj = &mutex->ptm_blocked;
(void)pthread__park(self, &mutex->ptm_interlock,
mutex, NULL, NULL, 0, 0);
&mutex->ptm_blocked, NULL, 0);
pthread_spinunlock(self, &mutex->ptm_interlock);
} else {
PTQ_REMOVE(&mutex->ptm_blocked, self, pt_sleep);
@ -377,7 +379,8 @@ pthread_mutex_unlock(pthread_mutex_t *mutex)
if ((blocked = PTQ_FIRST(&mutex->ptm_blocked)) != NULL) {
PTQ_REMOVE(&mutex->ptm_blocked, blocked, pt_sleep);
PTHREADD_ADD(PTHREADD_MUTEX_UNLOCK_UNBLOCK);
pthread__unpark(self, &mutex->ptm_interlock, mutex, blocked);
pthread__unpark(self, &mutex->ptm_interlock,
&mutex->ptm_blocked, blocked);
} else
pthread_spinunlock(self, &mutex->ptm_interlock);

View File

@ -1,11 +1,11 @@
/* $NetBSD: pthread_rwlock.c,v 1.16 2007/03/02 18:53:53 ad Exp $ */
/* $NetBSD: pthread_rwlock.c,v 1.17 2007/03/05 23:56:18 ad Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Nathan J. Williams.
* by Nathan J. Williams and Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread_rwlock.c,v 1.16 2007/03/02 18:53:53 ad Exp $");
__RCSID("$NetBSD: pthread_rwlock.c,v 1.17 2007/03/05 23:56:18 ad Exp $");
#include <errno.h>
@ -114,8 +114,11 @@ pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
*/
while ((rwlock->ptr_writer != NULL) ||
(!PTQ_EMPTY(&rwlock->ptr_wblocked))) {
PTQ_INSERT_TAIL(&rwlock->ptr_rblocked, self, pt_sleep);
self->pt_sleeponq = 1;
self->pt_sleepobj = &rwlock->ptr_rblocked;
(void)pthread__park(self, &rwlock->ptr_interlock,
rwlock, &rwlock->ptr_rblocked, NULL, 1, 0);
&rwlock->ptr_rblocked, NULL, 0);
}
rwlock->ptr_nreaders++;
@ -184,8 +187,11 @@ pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
return EDEADLK;
}
#endif
PTQ_INSERT_TAIL(&rwlock->ptr_wblocked, self, pt_sleep);
self->pt_sleeponq = 1;
self->pt_sleepobj = &rwlock->ptr_wblocked;
(void)pthread__park(self, &rwlock->ptr_interlock,
rwlock, &rwlock->ptr_wblocked, NULL, 1, 0);
&rwlock->ptr_wblocked, NULL, 0);
}
rwlock->ptr_writer = self;
@ -262,8 +268,11 @@ pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
retval = 0;
while ((retval == 0) && ((rwlock->ptr_writer != NULL) ||
(!PTQ_EMPTY(&rwlock->ptr_wblocked)))) {
PTQ_INSERT_TAIL(&rwlock->ptr_rblocked, self, pt_sleep);
self->pt_sleeponq = 1;
self->pt_sleepobj = &rwlock->ptr_rblocked;
retval = pthread__park(self, &rwlock->ptr_interlock,
rwlock, &rwlock->ptr_rblocked, abs_timeout, 1, 0);
&rwlock->ptr_rblocked, abs_timeout, 0);
}
/* One last chance to get the lock, in case it was released between
@ -320,8 +329,11 @@ pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
return EDEADLK;
}
#endif
PTQ_INSERT_TAIL(&rwlock->ptr_wblocked, self, pt_sleep);
self->pt_sleeponq = 1;
self->pt_sleepobj = &rwlock->ptr_wblocked;
retval = pthread__park(self, &rwlock->ptr_interlock,
rwlock, &rwlock->ptr_wblocked, abs_timeout, 1, 0);
&rwlock->ptr_wblocked, abs_timeout, 0);
}
if ((rwlock->ptr_nreaders == 0) && (rwlock->ptr_writer == NULL)) {
@ -380,9 +392,10 @@ pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
}
if (writer != NULL)
pthread__unpark(self, &rwlock->ptr_interlock, rwlock, writer);
pthread__unpark(self, &rwlock->ptr_interlock,
&rwlock->ptr_wblocked, writer);
else
pthread__unpark_all(self, &rwlock->ptr_interlock, rwlock,
pthread__unpark_all(self, &rwlock->ptr_interlock,
&rwlock->ptr_rblocked);
return 0;