Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpthread Define a pthread-specific assert function, pt...



details:   https://anonhg.NetBSD.org/src/rev/64fe78f6f291
branches:  trunk
changeset: 543039:64fe78f6f291
user:      nathanw <nathanw%NetBSD.org@localhost>
date:      Sat Feb 15 04:34:40 2003 +0000

description:
Define a pthread-specific assert function, pthread__assert(), that
bails out without trying to flush stdio buffers.

diffstat:

 lib/libpthread/pthread.c     |  48 +++++++++++++++++++++++++++++++++----------
 lib/libpthread/pthread_int.h |   9 ++++++-
 2 files changed, 44 insertions(+), 13 deletions(-)

diffs (157 lines):

diff -r 80cfeb605a42 -r 64fe78f6f291 lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c  Sat Feb 15 04:33:45 2003 +0000
+++ b/lib/libpthread/pthread.c  Sat Feb 15 04:34:40 2003 +0000
@@ -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 @@
  */
 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 @@
        pthread_barrier_init,
        pthread_key_create,
        &pthread__sched_binder,
+       &pthread__nanosleeping
 };
 
 /*
@@ -222,7 +223,7 @@
        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_exit(retval);
 
        /*NOTREACHED*//*CONSTCOND*/
-       assert(0);
+       pthread__assert(0);
 }
 
 
@@ -338,7 +339,7 @@
        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 @@
        }
 
        /*NOTREACHED*//*CONSTCOND*/
-       assert(0);
+       pthread__assert(0);
        exit(1);
 }
 
@@ -666,8 +667,10 @@
                } 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 @@
 
        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 -r 80cfeb605a42 -r 64fe78f6f291 lib/libpthread/pthread_int.h
--- a/lib/libpthread/pthread_int.h      Sat Feb 15 04:33:45 2003 +0000
+++ b/lib/libpthread/pthread_int.h      Sat Feb 15 04:34:40 2003 +0000
@@ -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 @@
 
 #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__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 */



Home | Main Index | Thread Index | Old Index