- Use pthread__cancelled() in more places.

- pthread_join(): assert that pthread_cond_wait() returns zero.
This commit is contained in:
ad 2007-12-24 16:04:20 +00:00
parent 1a1f7ef9de
commit 622bbc505a
5 changed files with 20 additions and 26 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread.c,v 1.94 2007/12/24 14:46:28 ad Exp $ */
/* $NetBSD: pthread.c,v 1.95 2007/12/24 16:04:20 ad Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread.c,v 1.94 2007/12/24 14:46:28 ad Exp $");
__RCSID("$NetBSD: pthread.c,v 1.95 2007/12/24 16:04:20 ad Exp $");
#define __EXPOSE_STACK 1
@ -77,7 +77,6 @@ static int pthread__stackalloc(pthread_t *);
static void pthread__initmain(pthread_t *);
static void pthread__fork_callback(void);
static void pthread__reap(pthread_t);
static void pthread__cancelled(void);
void pthread__init(void);
@ -577,19 +576,13 @@ pthread_join(pthread_t thread, void **valptr)
self->pt_droplock = NULL;
return EINVAL;
}
/*
* IEEE Std 1003.1, 2004 Edition:
*
* "The pthread_join() function shall not return an
* error code of [EINTR]."
*/
error = pthread_cond_wait(&thread->pt_joiners,
&thread->pt_lock);
if (error != 0 && error != EINTR) {
self->pt_droplock = NULL;
return error;
if (error != 0) {
pthread__errorfunc(__FILE__, __LINE__,
__func__, "unexpected return from cond_wait()");
}
}
if (valptr != NULL)
*valptr = thread->pt_exitval;

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread_cancelstub.c,v 1.16 2007/11/19 15:12:18 ad Exp $ */
/* $NetBSD: pthread_cancelstub.c,v 1.17 2007/12/24 16:04:21 ad Exp $ */
/*-
* Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread_cancelstub.c,v 1.16 2007/11/19 15:12:18 ad Exp $");
__RCSID("$NetBSD: pthread_cancelstub.c,v 1.17 2007/12/24 16:04:21 ad Exp $");
/*
* This is necessary because the names are always weak (they are not
@ -116,7 +116,7 @@ int __sigsuspend14(const sigset_t *);
#define TESTCANCEL(id) do { \
if (__predict_false((id)->pt_cancel)) \
pthread_exit(PTHREAD_CANCELED); \
pthread__cancelled(); \
} while (/*CONSTCOND*/0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread_cond.c,v 1.39 2007/11/19 15:14:12 ad Exp $ */
/* $NetBSD: pthread_cond.c,v 1.40 2007/12/24 16:04:21 ad Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread_cond.c,v 1.39 2007/11/19 15:14:12 ad Exp $");
__RCSID("$NetBSD: pthread_cond.c,v 1.40 2007/12/24 16:04:21 ad Exp $");
#include <errno.h>
#include <sys/time.h>
@ -110,7 +110,7 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
return pthread_cond_wait_nothread(self, mutex, NULL);
if (__predict_false(self->pt_cancel))
pthread_exit(PTHREAD_CANCELED);
pthread__cancelled();
/*
* Note this thread as waiting on the CV. To ensure good
@ -170,7 +170,7 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
if (__predict_false(self->pt_cancel)) {
if (self->pt_signalled)
pthread_cond_signal(cond);
pthread_exit(PTHREAD_CANCELED);
pthread__cancelled();
}
return 0;
@ -200,7 +200,7 @@ pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
return pthread_cond_wait_nothread(self, mutex, abstime);
if (__predict_false(self->pt_cancel))
pthread_exit(PTHREAD_CANCELED);
pthread__cancelled();
/*
* Note this thread as waiting on the CV. To ensure good
@ -261,7 +261,7 @@ pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
if (self->pt_signalled)
pthread_cond_signal(cond);
if (self->pt_cancel)
pthread_exit(PTHREAD_CANCELED);
pthread__cancelled();
}
return retval;

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread_int.h,v 1.63 2007/12/24 14:46:29 ad Exp $ */
/* $NetBSD: pthread_int.h,v 1.64 2007/12/24 16:04:21 ad Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007 The NetBSD Foundation, Inc.
@ -282,6 +282,7 @@ void pthread__assertfunc(const char *, int, const char *, const char *)
void pthread__errorfunc(const char *, int, const char *, const char *)
PTHREAD_HIDE;
char *pthread__getenv(const char *) PTHREAD_HIDE;
void pthread__cancelled(void) PTHREAD_HIDE;
void *pthread__atomic_cas_ptr(volatile void *, const void *, const void *) PTHREAD_HIDE;
void *pthread__atomic_swap_ptr(volatile void *, const void *) PTHREAD_HIDE;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sem.c,v 1.18 2007/09/14 09:15:41 tnn Exp $ */
/* $NetBSD: sem.c,v 1.19 2007/12/24 16:04:21 ad Exp $ */
/*-
* Copyright (c) 2003, 2006, 2007 The NetBSD Foundation, Inc.
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: sem.c,v 1.18 2007/09/14 09:15:41 tnn Exp $");
__RCSID("$NetBSD: sem.c,v 1.19 2007/12/24 16:04:21 ad Exp $");
#include <sys/types.h>
#include <sys/ksem.h>
@ -323,7 +323,7 @@ sem_wait(sem_t *sem)
for (;;) {
if (self->pt_cancel) {
pthread_mutex_unlock(&(*sem)->usem_interlock);
pthread_exit(PTHREAD_CANCELED);
pthread__cancelled();
}
if ((*sem)->usem_count > 0)
break;