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. * Copyright (c) 2001, 2003, 2006, 2007 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
* *
* This code is derived from software contributed to The NetBSD Foundation * 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -37,7 +37,7 @@
*/ */
#include <sys/cdefs.h> #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> #include <errno.h>
@ -167,7 +167,7 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
self, barrier)); self, barrier));
barrier->ptb_generation++; barrier->ptb_generation++;
pthread__unpark_all(self, &barrier->ptb_lock, barrier, pthread__unpark_all(self, &barrier->ptb_lock,
&barrier->ptb_waiters); &barrier->ptb_waiters);
return PTHREAD_BARRIER_SERIAL_THREAD; return PTHREAD_BARRIER_SERIAL_THREAD;
} }
@ -177,8 +177,11 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
while (gen == barrier->ptb_generation) { while (gen == barrier->ptb_generation) {
SDPRINTF(("(barrier wait %p) Waiting on %p\n", SDPRINTF(("(barrier wait %p) Waiting on %p\n",
self, barrier)); self, barrier));
(void)pthread__park(self, &barrier->ptb_lock, barrier, PTQ_INSERT_TAIL(&barrier->ptb_waiters, self, pt_sleep);
&barrier->ptb_waiters, NULL, 1, 0); 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", SDPRINTF(("(barrier wait %p) Woke up on %p\n",
self, barrier)); 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. * Copyright (c) 2001, 2003, 2006, 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/ */
#include <sys/cdefs.h> #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 <errno.h>
#include <limits.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 * but it's okay since we're just going to
* retry. * retry.
*/ */
self->pt_sleeponq = 1;
self->pt_sleepobj = &mutex->ptm_blocked;
(void)pthread__park(self, &mutex->ptm_interlock, (void)pthread__park(self, &mutex->ptm_interlock,
mutex, NULL, NULL, 0, 0); &mutex->ptm_blocked, NULL, 0);
pthread_spinunlock(self, &mutex->ptm_interlock); pthread_spinunlock(self, &mutex->ptm_interlock);
} else { } else {
PTQ_REMOVE(&mutex->ptm_blocked, self, pt_sleep); 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) { if ((blocked = PTQ_FIRST(&mutex->ptm_blocked)) != NULL) {
PTQ_REMOVE(&mutex->ptm_blocked, blocked, pt_sleep); PTQ_REMOVE(&mutex->ptm_blocked, blocked, pt_sleep);
PTHREADD_ADD(PTHREADD_MUTEX_UNLOCK_UNBLOCK); 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 } else
pthread_spinunlock(self, &mutex->ptm_interlock); 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. * Copyright (c) 2002, 2006, 2007 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
* *
* This code is derived from software contributed to The NetBSD Foundation * 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -37,7 +37,7 @@
*/ */
#include <sys/cdefs.h> #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> #include <errno.h>
@ -114,8 +114,11 @@ pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
*/ */
while ((rwlock->ptr_writer != NULL) || while ((rwlock->ptr_writer != NULL) ||
(!PTQ_EMPTY(&rwlock->ptr_wblocked))) { (!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, (void)pthread__park(self, &rwlock->ptr_interlock,
rwlock, &rwlock->ptr_rblocked, NULL, 1, 0); &rwlock->ptr_rblocked, NULL, 0);
} }
rwlock->ptr_nreaders++; rwlock->ptr_nreaders++;
@ -184,8 +187,11 @@ pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
return EDEADLK; return EDEADLK;
} }
#endif #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, (void)pthread__park(self, &rwlock->ptr_interlock,
rwlock, &rwlock->ptr_wblocked, NULL, 1, 0); &rwlock->ptr_wblocked, NULL, 0);
} }
rwlock->ptr_writer = self; rwlock->ptr_writer = self;
@ -262,8 +268,11 @@ pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
retval = 0; retval = 0;
while ((retval == 0) && ((rwlock->ptr_writer != NULL) || while ((retval == 0) && ((rwlock->ptr_writer != NULL) ||
(!PTQ_EMPTY(&rwlock->ptr_wblocked)))) { (!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, 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 /* 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; return EDEADLK;
} }
#endif #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, 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)) { if ((rwlock->ptr_nreaders == 0) && (rwlock->ptr_writer == NULL)) {
@ -380,9 +392,10 @@ pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
} }
if (writer != NULL) if (writer != NULL)
pthread__unpark(self, &rwlock->ptr_interlock, rwlock, writer); pthread__unpark(self, &rwlock->ptr_interlock,
&rwlock->ptr_wblocked, writer);
else else
pthread__unpark_all(self, &rwlock->ptr_interlock, rwlock, pthread__unpark_all(self, &rwlock->ptr_interlock,
&rwlock->ptr_rblocked); &rwlock->ptr_rblocked);
return 0; return 0;