Use pthread__error() instead of pthread__abort().

This commit is contained in:
nathanw 2003-04-23 19:36:12 +00:00
parent df2772713e
commit 3f6de8d84a
2 changed files with 55 additions and 31 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread_cond.c,v 1.10 2003/04/18 21:36:38 nathanw Exp $ */
/* $NetBSD: pthread_cond.c,v 1.11 2003/04/23 19:36:12 nathanw Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread_cond.c,v 1.10 2003/04/18 21:36:38 nathanw Exp $");
__RCSID("$NetBSD: pthread_cond.c,v 1.11 2003/04/23 19:36:12 nathanw Exp $");
#include <errno.h>
#include <sys/time.h>
@ -71,8 +71,8 @@ int
pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
{
pthread__assert((attr == NULL) ||
(attr->ptca_magic == _PT_CONDATTR_MAGIC));
pthread__error(EINVAL, "Invalid condition variable attribute",
(attr == NULL) || (attr->ptca_magic == _PT_CONDATTR_MAGIC));
cond->ptc_magic = _PT_COND_MAGIC;
pthread_lockinit(&cond->ptc_lock);
@ -87,8 +87,10 @@ int
pthread_cond_destroy(pthread_cond_t *cond)
{
pthread__assert(cond->ptc_magic == _PT_COND_MAGIC);
pthread__assert(cond->ptc_mutex == NULL);
pthread__error(EINVAL, "Invalid condition variable",
cond->ptc_magic == _PT_COND_MAGIC);
pthread__error(EBUSY, "Destroying condition variable in use",
cond->ptc_mutex == NULL);
cond->ptc_magic = _PT_COND_DEAD;
@ -101,9 +103,12 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
pthread_t self;
pthread__assert(cond->ptc_magic == _PT_COND_MAGIC);
pthread__assert(mutex->ptm_magic == _PT_MUTEX_MAGIC);
pthread__assert(mutex->ptm_lock == __SIMPLELOCK_LOCKED);
pthread__error(EINVAL, "Invalid condition variable",
cond->ptc_magic == _PT_COND_MAGIC);
pthread__error(EINVAL, "Invalid mutex",
mutex->ptm_magic == _PT_MUTEX_MAGIC);
pthread__error(EPERM, "Mutex not locked in condition wait",
mutex->ptm_lock == __SIMPLELOCK_LOCKED);
self = pthread__self();
PTHREADD_ADD(PTHREADD_COND_WAIT);
@ -117,7 +122,9 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
if (cond->ptc_mutex == NULL)
cond->ptc_mutex = mutex;
else
pthread__assert(cond->ptc_mutex == mutex);
pthread__error(EINVAL,
"Multiple mutexes used for condition wait",
cond->ptc_mutex == mutex);
#endif
SDPRINTF(("(cond wait %p) Waiting on %p, mutex %p\n",
@ -162,10 +169,14 @@ pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
struct pt_alarm_t alarm;
int retval;
pthread__assert(cond->ptc_magic == _PT_COND_MAGIC);
pthread__assert(mutex->ptm_magic == _PT_MUTEX_MAGIC);
pthread__assert(mutex->ptm_lock == __SIMPLELOCK_LOCKED);
pthread__assert((abstime->tv_sec >= 0) &&
pthread__error(EINVAL, "Invalid condition variable",
cond->ptc_magic == _PT_COND_MAGIC);
pthread__error(EINVAL, "Invalid mutex",
mutex->ptm_magic == _PT_MUTEX_MAGIC);
pthread__error(EPERM, "Mutex not locked in condition wait",
mutex->ptm_lock == __SIMPLELOCK_LOCKED);
pthread__error(EINVAL, "Invalid wait time",
(abstime->tv_sec >= 0) &&
(abstime->tv_nsec >= 0) && (abstime->tv_nsec < 1000000000));
self = pthread__self();
@ -180,7 +191,9 @@ pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
if (cond->ptc_mutex == NULL)
cond->ptc_mutex = mutex;
else
pthread__assert(cond->ptc_mutex == mutex);
pthread__error(EINVAL,
"Multiple mutexes used for condition wait",
cond->ptc_mutex == mutex);
#endif
wait.ptw_thread = self;
@ -253,7 +266,8 @@ pthread_cond_signal(pthread_cond_t *cond)
{
pthread_t self, signaled;
pthread__assert(cond->ptc_magic == _PT_COND_MAGIC);
pthread__error(EINVAL, "Invalid condition variable",
cond->ptc_magic == _PT_COND_MAGIC);
PTHREADD_ADD(PTHREADD_COND_SIGNAL);
SDPRINTF(("(cond signal %p) Signaling %p\n",
@ -286,7 +300,7 @@ pthread_cond_broadcast(pthread_cond_t *cond)
pthread_t self;
struct pthread_queue_t blockedq;
pthread__assert(cond->ptc_magic == _PT_COND_MAGIC);
pthread__error(EINVAL, "Invalid condition variable", cond->ptc_magic == _PT_COND_MAGIC);
PTHREADD_ADD(PTHREADD_COND_BROADCAST);
SDPRINTF(("(cond signal %p) Broadcasting %p\n",
@ -324,7 +338,8 @@ int
pthread_condattr_destroy(pthread_condattr_t *attr)
{
pthread__assert(attr->ptca_magic == _PT_CONDATTR_MAGIC);
pthread__error(EINVAL, "Invalid condition variable attribute",
attr->ptca_magic == _PT_CONDATTR_MAGIC);
attr->ptca_magic = _PT_CONDATTR_DEAD;

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread_mutex.c,v 1.13 2003/04/18 21:36:38 nathanw Exp $ */
/* $NetBSD: pthread_mutex.c,v 1.14 2003/04/23 19:36:12 nathanw Exp $ */
/*-
* Copyright (c) 2001, 2003 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread_mutex.c,v 1.13 2003/04/18 21:36:38 nathanw Exp $");
__RCSID("$NetBSD: pthread_mutex.c,v 1.14 2003/04/23 19:36:12 nathanw Exp $");
#include <errno.h>
#include <limits.h>
@ -98,8 +98,8 @@ pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
struct mutexattr_private *map;
struct mutex_private *mp;
pthread__assert((attr == NULL) ||
(attr->ptma_magic == _PT_MUTEXATTR_MAGIC));
pthread__error(EINVAL, "Invalid mutex attribute",
(attr == NULL) || (attr->ptma_magic == _PT_MUTEXATTR_MAGIC));
if (attr != NULL && (map = attr->ptma_private) != NULL &&
memcmp(map, &mutexattr_private_default, sizeof(*map)) != 0) {
@ -129,8 +129,10 @@ int
pthread_mutex_destroy(pthread_mutex_t *mutex)
{
pthread__assert(mutex->ptm_magic == _PT_MUTEX_MAGIC);
pthread__assert(mutex->ptm_lock == __SIMPLELOCK_UNLOCKED);
pthread__error(EINVAL, "Invalid mutex",
mutex->ptm_magic == _PT_MUTEX_MAGIC);
pthread__error(EBUSY, "Destroying locked mutex",
mutex->ptm_lock == __SIMPLELOCK_UNLOCKED);
mutex->ptm_magic = _PT_MUTEX_DEAD;
if (mutex->ptm_private != NULL &&
@ -188,7 +190,8 @@ pthread_mutex_lock_slow(pthread_mutex_t *mutex)
{
pthread_t self;
pthread__assert(mutex->ptm_magic == _PT_MUTEX_MAGIC);
pthread__error(EINVAL, "Invalid mutex",
mutex->ptm_magic == _PT_MUTEX_MAGIC);
self = pthread__self();
@ -266,7 +269,8 @@ int
pthread_mutex_trylock(pthread_mutex_t *mutex)
{
pthread__assert(mutex->ptm_magic == _PT_MUTEX_MAGIC);
pthread__error(EINVAL, "Invalid mutex",
mutex->ptm_magic == _PT_MUTEX_MAGIC);
PTHREADD_ADD(PTHREADD_MUTEX_TRYLOCK);
if (pthread__simple_lock_try(&mutex->ptm_lock) == 0) {
@ -304,7 +308,8 @@ pthread_mutex_unlock(pthread_mutex_t *mutex)
pthread_t self, blocked;
int weown;
pthread__assert(mutex->ptm_magic == _PT_MUTEX_MAGIC);
pthread__error(EINVAL, "Invalid mutex",
mutex->ptm_magic == _PT_MUTEX_MAGIC);
PTHREADD_ADD(PTHREADD_MUTEX_UNLOCK);
@ -329,7 +334,8 @@ pthread_mutex_unlock(pthread_mutex_t *mutex)
if (!weown)
return EPERM;
default:
pthread__assert(weown);
pthread__error(EPERM,
"Unlocking mutex owned by another thread", weown);
break;
}
@ -384,7 +390,8 @@ int
pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
{
pthread__assert(attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
pthread__error(EINVAL, "Invalid mutex attribute",
attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
attr->ptma_magic = _PT_MUTEXATTR_DEAD;
if (attr->ptma_private != NULL)
@ -399,7 +406,8 @@ pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *typep)
{
struct mutexattr_private *map;
pthread__assert(attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
pthread__error(EINVAL, "Invalid mutex attribute",
attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
map = attr->ptma_private;
@ -414,7 +422,8 @@ pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
{
struct mutexattr_private *map;
pthread__assert(attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
pthread__error(EINVAL, "Invalid mutex attribute",
attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
map = attr->ptma_private;