diff options
| author | nathanw <nathanw@NetBSD.org> | 2003-02-15 04:34:40 +0000 |
|---|---|---|
| committer | nathanw <nathanw@NetBSD.org> | 2003-02-15 04:34:40 +0000 |
| commit | 8bcff70bb04222dd780511d1d73cf2e8473bcd08 (patch) | |
| tree | c2232fd12e8e490575f0f0507cef712180881d5b /lib/libpthread | |
| parent | e0ae1bd1b76d647d57a34b0ce31767f1ef567fb4 (diff) | |
Define a pthread-specific assert function, pthread__assert(), that
bails out without trying to flush stdio buffers.
Diffstat (limited to 'lib/libpthread')
| -rw-r--r-- | lib/libpthread/pthread.c | 48 | ||||
| -rw-r--r-- | lib/libpthread/pthread_int.h | 9 |
2 files changed, 44 insertions, 13 deletions
diff --git a/lib/libpthread/pthread.c b/lib/libpthread/pthread.c index feea672d2aa..81968d5b34d 100644 --- a/lib/libpthread/pthread.c +++ b/lib/libpthread/pthread.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread.c,v 1.8 2003/01/31 04:59:40 nathanw Exp $ */ +/* $NetBSD: pthread.c,v 1.9 2003/02/15 04:34:40 nathanw Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -36,23 +36,22 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include <assert.h> #include <err.h> #include <errno.h> #include <lwp.h> #include <signal.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ucontext.h> +#include <unistd.h> + #include <sys/cdefs.h> #include <sched.h> #include "pthread.h" #include "pthread_int.h" - -#undef PTHREAD_MAIN_DEBUG - #ifdef PTHREAD_MAIN_DEBUG #define SDPRINTF(x) DPRINTF(x) #else @@ -90,6 +89,7 @@ __strong_alias(__libc_thr_errno,pthread__errno) */ extern int pthread__cancel_stub_binder; extern int pthread__sched_binder; +extern struct pthread_queue_t pthread__nanosleeping; void *pthread__static_lib_binder[] = { &pthread__cancel_stub_binder, @@ -99,6 +99,7 @@ void *pthread__static_lib_binder[] = { pthread_barrier_init, pthread_key_create, &pthread__sched_binder, + &pthread__nanosleeping }; /* @@ -222,7 +223,7 @@ pthread_create(pthread_t *thread, const pthread_attr_t *attr, int ret; PTHREADD_ADD(PTHREADD_CREATE); - assert(thread != NULL); + pthread__assert(thread != NULL); /* * It's okay to check this without a lock because there can @@ -299,7 +300,7 @@ pthread__create_tramp(void *(*start)(void *), void *arg) pthread_exit(retval); /*NOTREACHED*//*CONSTCOND*/ - assert(0); + pthread__assert(0); } @@ -338,7 +339,7 @@ pthread__idle(void) self->pt_spinlocks++; /* XXX make sure we get to finish the assert! */ SDPRINTF(("(pthread__idle %p) Returned! Error.\n", self)); /* CONSTCOND */ - assert(0); + pthread__assert(0); } @@ -406,7 +407,7 @@ pthread_exit(void *retval) } /*NOTREACHED*//*CONSTCOND*/ - assert(0); + pthread__assert(0); exit(1); } @@ -666,8 +667,10 @@ pthread_cancel(pthread_t thread) } else if (thread->pt_state == PT_STATE_BLOCKED_QUEUE) { /* * We're blocked somewhere (pthread__block() - * was called. Cause it to wake up and the - * caller will check for the cancellation. + * was called). Cause it to wake up; it will + * check for the cancellation if the routine + * is a cancellation point, and loop and reblock + * otherwise. */ pthread_spinlock(self, thread->pt_sleeplock); PTQ_REMOVE(thread->pt_sleepq, thread, @@ -843,3 +846,26 @@ pthread__errno(void) return &(self->pt_errno); } + +void +pthread__assertfunc(char *file, int line, char *function, char *expr) +{ + char buf[1024]; + int len; + + /* + * snprintf should not acquire any locks, or we could + * end up deadlocked if the assert caller held locks. + */ + len = snprintf(buf, 1024, + "assertion \"%s\" failed: file \"%s\", line %d%s%s%s\n", + expr, file, line, + function ? ", function \"" : "", + function ? function : "", + function ? "\"" : ""); + + write(STDERR_FILENO, buf, len); + (void)kill(getpid(), SIGABRT); + + _exit(1); +} diff --git a/lib/libpthread/pthread_int.h b/lib/libpthread/pthread_int.h index 9f03a27ca07..76b987a1b5e 100644 --- a/lib/libpthread/pthread_int.h +++ b/lib/libpthread/pthread_int.h @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_int.h,v 1.6 2003/02/04 20:14:10 jdolecek Exp $ */ +/* $NetBSD: pthread_int.h,v 1.7 2003/02/15 04:34:40 nathanw Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -334,6 +334,11 @@ void pthread__sigcontext_to_ucontext(const struct pthread__sigcontext *, #define pthread__self() (pthread__id(pthread__sp())) +#define pthread__assert(e) \ + ((e) ? __static_cast(void,0) : \ + pthread__assertfunc(__FILE__, __LINE__, __func__, #e)) + + /* These three routines are defined in processor-specific code. */ void pthread__upcall_switch(pthread_t self, pthread_t next); void pthread__switch(pthread_t self, pthread_t next); @@ -347,6 +352,6 @@ void pthread__deliver_signal(pthread_t self, pthread_t t, int sig, int code); void pthread__signal_deferred(pthread_t self, pthread_t t); void pthread__destroy_tsd(pthread_t self); - +void pthread__assertfunc(char *file, int line, char *function, char *expr); #endif /* _LIB_PTHREAD_INT_H */ |
