Remove the debuglog stuff. ktrace is more useful now.
This commit is contained in:
parent
a448c4f214
commit
8077340e63
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.46 2007/11/13 17:20:08 ad Exp $
|
||||
# $NetBSD: Makefile,v 1.47 2007/11/19 15:14:11 ad Exp $
|
||||
#
|
||||
|
||||
WARNS= 4
|
||||
@ -60,7 +60,6 @@ SRCS+= pthread_rwlock2.c
|
||||
SRCS+= pthread_specific.c
|
||||
SRCS+= pthread_spin.c
|
||||
SRCS+= pthread_tsd.c
|
||||
SRCS+= pthread_debug.c
|
||||
SRCS+= res_state.c
|
||||
SRCS+= sched.c
|
||||
SRCS+= sem.c
|
||||
@ -149,9 +148,6 @@ MLINKS+= pthread_testcancel.3 pthread_setcanceltype.3
|
||||
|
||||
pthread_switch.S _context_u.S: assym.h
|
||||
|
||||
debuglog: debuglog.o
|
||||
$(CC) -o debuglog debuglog.o -lpthread
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
|
||||
.else
|
||||
|
@ -1,160 +0,0 @@
|
||||
/* $NetBSD: debuglog.c,v 1.7 2007/03/02 18:53:51 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Nathan J. Williams.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
#include "pthread.h"
|
||||
#include "pthread_int.h"
|
||||
|
||||
|
||||
void pthread__debuglog_read(int, int);
|
||||
void pthread__debuglog_rawdump(void);
|
||||
|
||||
void usage(void);
|
||||
|
||||
|
||||
static struct pthread_msgbuf* debugbuf;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
|
||||
int follow, initialize, raw, keep;
|
||||
|
||||
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
|
||||
|
||||
follow = 0;
|
||||
initialize = 0;
|
||||
raw = 0;
|
||||
keep = 0;
|
||||
|
||||
while ((ch = getopt(argc, argv, "rfik")) != -1)
|
||||
switch (ch) {
|
||||
case 'k':
|
||||
keep = 1;
|
||||
break;
|
||||
case 'r':
|
||||
raw = 1;
|
||||
break;
|
||||
case 'f':
|
||||
follow = 1;
|
||||
break;
|
||||
case 'i':
|
||||
initialize = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc != 0)
|
||||
usage();
|
||||
|
||||
debugbuf = pthread__debuglog_init(initialize);
|
||||
|
||||
if (raw)
|
||||
pthread__debuglog_rawdump();
|
||||
else
|
||||
pthread__debuglog_read(follow, !keep);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
pthread__debuglog_rawdump(void)
|
||||
{
|
||||
|
||||
printf("Debug log raw dump\n");
|
||||
printf("Magic: %06x\n", debugbuf->msg_magic);
|
||||
printf("Size: %06llx\n", (long long)debugbuf->msg_bufs);
|
||||
printf("Read start: %ld Write start: %ld\n\n",
|
||||
(long)debugbuf->msg_bufr, (long)debugbuf->msg_bufw);
|
||||
|
||||
fwrite(&debugbuf->msg_bufc[0], debugbuf->msg_bufs, 1, stdout);
|
||||
}
|
||||
|
||||
void
|
||||
pthread__debuglog_read(int follow, int trunc)
|
||||
{
|
||||
|
||||
int readp, writep;
|
||||
|
||||
do {
|
||||
|
||||
readp = debugbuf->msg_bufr;
|
||||
writep = debugbuf->msg_bufw;
|
||||
|
||||
if (readp < writep) {
|
||||
fwrite(&debugbuf->msg_bufc[readp], writep - readp,
|
||||
1, stdout);
|
||||
} else if (readp > writep) {
|
||||
fwrite(&debugbuf->msg_bufc[readp],
|
||||
debugbuf->msg_bufs - readp, 1, stdout);
|
||||
fwrite(&debugbuf->msg_bufc[0], writep, 1, stdout);
|
||||
}
|
||||
|
||||
if (trunc)
|
||||
debugbuf->msg_bufr = writep;
|
||||
|
||||
if (follow)
|
||||
sched_yield();
|
||||
} while (follow);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void usage()
|
||||
{
|
||||
|
||||
fprintf(stderr,"usage: debuglog [-fi]\n");
|
||||
exit(1);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pthread.c,v 1.89 2007/11/14 19:28:23 drochner Exp $ */
|
||||
/* $NetBSD: pthread.c,v 1.90 2007/11/19 15:14:12 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.89 2007/11/14 19:28:23 drochner Exp $");
|
||||
__RCSID("$NetBSD: pthread.c,v 1.90 2007/11/19 15:14:12 ad Exp $");
|
||||
|
||||
#define __EXPOSE_STACK 1
|
||||
|
||||
@ -204,7 +204,6 @@ pthread__init(void)
|
||||
|
||||
/* Start subsystems */
|
||||
PTHREAD_MD_INIT
|
||||
pthread__debug_init();
|
||||
|
||||
for (p = pthread__getenv("PTHREAD_DIAGASSERT"); p && *p; p++) {
|
||||
switch (*p) {
|
||||
@ -327,8 +326,6 @@ pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
unsigned long flag;
|
||||
int ret;
|
||||
|
||||
PTHREADD_ADD(PTHREADD_CREATE);
|
||||
|
||||
/*
|
||||
* It's okay to check this without a lock because there can
|
||||
* only be one thread before it becomes true.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pthread_barrier.c,v 1.15 2007/11/13 15:57:11 ad Exp $ */
|
||||
/* $NetBSD: pthread_barrier.c,v 1.16 2007/11/19 15:14:12 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001, 2003, 2006, 2007 The NetBSD Foundation, Inc.
|
||||
@ -37,21 +37,13 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: pthread_barrier.c,v 1.15 2007/11/13 15:57:11 ad Exp $");
|
||||
__RCSID("$NetBSD: pthread_barrier.c,v 1.16 2007/11/19 15:14:12 ad Exp $");
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "pthread.h"
|
||||
#include "pthread_int.h"
|
||||
|
||||
#undef PTHREAD_BARRIER_DEBUG
|
||||
|
||||
#ifdef PTHREAD_BARRIER_DEBUG
|
||||
#define SDPRINTF(x) DPRINTF(x)
|
||||
#else
|
||||
#define SDPRINTF(x)
|
||||
#endif
|
||||
|
||||
int
|
||||
pthread_barrier_init(pthread_barrier_t *barrier,
|
||||
const pthread_barrierattr_t *attr, unsigned int count)
|
||||
@ -162,9 +154,6 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
|
||||
* but instead is responsible for waking everyone else up.
|
||||
*/
|
||||
if (barrier->ptb_curcount + 1 == barrier->ptb_initcount) {
|
||||
SDPRINTF(("(barrier wait %p) Satisfied %p\n",
|
||||
self, barrier));
|
||||
|
||||
barrier->ptb_generation++;
|
||||
pthread__unpark_all(self, &barrier->ptb_lock,
|
||||
&barrier->ptb_waiters);
|
||||
@ -174,8 +163,6 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
|
||||
barrier->ptb_curcount++;
|
||||
gen = barrier->ptb_generation;
|
||||
while (gen == barrier->ptb_generation) {
|
||||
SDPRINTF(("(barrier wait %p) Waiting on %p\n",
|
||||
self, barrier));
|
||||
PTQ_INSERT_TAIL(&barrier->ptb_waiters, self, pt_sleep);
|
||||
self->pt_sleeponq = 1;
|
||||
self->pt_sleepobj = &barrier->ptb_waiters;
|
||||
@ -183,8 +170,6 @@ pthread_barrier_wait(pthread_barrier_t *barrier)
|
||||
(void)pthread__park(self, &barrier->ptb_lock,
|
||||
&barrier->ptb_waiters, NULL, 0,
|
||||
&barrier->ptb_waiters);
|
||||
SDPRINTF(("(barrier wait %p) Woke up on %p\n",
|
||||
self, barrier));
|
||||
pthread__spinlock(self, &barrier->ptb_lock);
|
||||
}
|
||||
pthread__spinunlock(self, &barrier->ptb_lock);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pthread_cond.c,v 1.38 2007/11/13 15:57:11 ad Exp $ */
|
||||
/* $NetBSD: pthread_cond.c,v 1.39 2007/11/19 15:14:12 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.38 2007/11/13 15:57:11 ad Exp $");
|
||||
__RCSID("$NetBSD: pthread_cond.c,v 1.39 2007/11/19 15:14:12 ad Exp $");
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
@ -104,7 +104,6 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
mutex->ptm_owner != NULL);
|
||||
|
||||
self = pthread__self();
|
||||
PTHREADD_ADD(PTHREADD_COND_WAIT);
|
||||
|
||||
/* Just hang out for a while if threads aren't running yet. */
|
||||
if (__predict_false(pthread__started == 0))
|
||||
@ -195,7 +194,6 @@ pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
||||
(abstime->tv_nsec >= 0) && (abstime->tv_nsec < 1000000000));
|
||||
|
||||
self = pthread__self();
|
||||
PTHREADD_ADD(PTHREADD_COND_TIMEDWAIT);
|
||||
|
||||
/* Just hang out for a while if threads aren't running yet. */
|
||||
if (__predict_false(pthread__started == 0))
|
||||
@ -277,7 +275,6 @@ pthread_cond_signal(pthread_cond_t *cond)
|
||||
|
||||
pthread__error(EINVAL, "Invalid condition variable",
|
||||
cond->ptc_magic == _PT_COND_MAGIC);
|
||||
PTHREADD_ADD(PTHREADD_COND_SIGNAL);
|
||||
|
||||
if (PTQ_EMPTY(&cond->ptc_waiters))
|
||||
return 0;
|
||||
@ -334,7 +331,6 @@ pthread_cond_signal(pthread_cond_t *cond)
|
||||
pthread__unpark(self, &cond->ptc_lock,
|
||||
&cond->ptc_waiters, signaled);
|
||||
}
|
||||
PTHREADD_ADD(PTHREADD_COND_WOKEUP);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -349,8 +345,6 @@ pthread_cond_broadcast(pthread_cond_t *cond)
|
||||
pthread__error(EINVAL, "Invalid condition variable",
|
||||
cond->ptc_magic == _PT_COND_MAGIC);
|
||||
|
||||
PTHREADD_ADD(PTHREADD_COND_BROADCAST);
|
||||
|
||||
if (PTQ_EMPTY(&cond->ptc_waiters))
|
||||
return 0;
|
||||
|
||||
@ -387,11 +381,7 @@ pthread_cond_broadcast(pthread_cond_t *cond)
|
||||
}
|
||||
}
|
||||
pthread__unpark_all(self, &cond->ptc_lock, &cond->ptc_waiters);
|
||||
|
||||
PTHREADD_ADD(PTHREADD_COND_WOKEUP);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,232 +0,0 @@
|
||||
/* $NetBSD: pthread_debug.c,v 1.14 2007/11/13 15:57:11 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001, 2006, 2007 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Nathan J. Williams.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: pthread_debug.c,v 1.14 2007/11/13 15:57:11 ad Exp $");
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "pthread.h"
|
||||
#include "pthread_int.h"
|
||||
|
||||
int pthread__dbg;
|
||||
|
||||
#ifdef PTHREAD__DEBUG
|
||||
|
||||
int pthread__debug_counters[PTHREADD_NCOUNTERS];
|
||||
static struct pthread_msgbuf *debugbuf;
|
||||
#define MAXLINELEN 1000
|
||||
struct linebuf {
|
||||
char buf[MAXLINELEN];
|
||||
int len;
|
||||
};
|
||||
static struct linebuf *linebuf;
|
||||
|
||||
static void pthread__debug_printcounters(void);
|
||||
static const char *pthread__counternames[] = PTHREADD_INITCOUNTERNAMES;
|
||||
|
||||
extern int pthread__started;
|
||||
|
||||
void
|
||||
pthread__debug_init(void)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
if (pthread__getenv("PTHREAD_DEBUGCOUNTERS") != NULL)
|
||||
atexit(pthread__debug_printcounters);
|
||||
|
||||
if (pthread__getenv("PTHREAD_DEBUGLOG") != NULL) {
|
||||
t = time(NULL);
|
||||
debugbuf = pthread__debuglog_init(0);
|
||||
linebuf = calloc(1000, sizeof(struct linebuf));
|
||||
if (linebuf == NULL)
|
||||
err(1, "Couldn't allocate linebuf");
|
||||
|
||||
DPRINTF(("Started debugging %s (pid %d) at %s\n",
|
||||
getprogname(), getpid(), ctime(&t)));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pthread__debug_printcounters(void)
|
||||
{
|
||||
int i;
|
||||
int counts[PTHREADD_NCOUNTERS];
|
||||
|
||||
/*
|
||||
* Copy the counters before printing anything to so that we don't see
|
||||
* the effect of printing the counters.
|
||||
* There will still be one more mutex lock than unlock, because
|
||||
* atexit() handling itself will call us back with a mutex locked.
|
||||
*/
|
||||
for (i = 0; i < PTHREADD_NCOUNTERS; i++)
|
||||
counts[i] = pthread__debug_counters[i];
|
||||
|
||||
printf("Pthread event counters\n");
|
||||
for (i = 0; i < PTHREADD_NCOUNTERS; i++)
|
||||
printf("%2d %-20s %9d\n", i, pthread__counternames[i],
|
||||
counts[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
struct pthread_msgbuf *
|
||||
pthread__debuglog_init(int force)
|
||||
{
|
||||
int debugshmid;
|
||||
void *debuglog;
|
||||
struct pthread_msgbuf* buf;
|
||||
|
||||
debugshmid = shmget((key_t)PTHREAD__DEBUG_SHMKEY,
|
||||
PTHREAD__DEBUG_SHMSIZE, IPC_CREAT | S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
|
||||
if (debugshmid == -1)
|
||||
err(1, "Couldn't get shared debug log");
|
||||
|
||||
debuglog = shmat(debugshmid, 0, 0);
|
||||
|
||||
if (debuglog == (void *)-1)
|
||||
err(1, "Couldn't map shared debug log (ID %d)", debugshmid);
|
||||
|
||||
buf = (struct pthread_msgbuf *)debuglog;
|
||||
|
||||
if (force || buf->msg_magic != BUF_MAGIC) {
|
||||
/* Initialize */
|
||||
buf->msg_magic = BUF_MAGIC;
|
||||
buf->msg_bufw = 0;
|
||||
buf->msg_bufr = 0;
|
||||
buf->msg_bufs = PTHREAD__DEBUG_SHMSIZE -
|
||||
sizeof (struct pthread_msgbuf);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void
|
||||
pthread__debuglog_printf(const char *fmt, ...)
|
||||
{
|
||||
char *tmpbuf;
|
||||
size_t len, cplen, r, w, s;
|
||||
long diff1, diff2;
|
||||
int vpid;
|
||||
va_list ap;
|
||||
|
||||
if (debugbuf == NULL || linebuf == NULL)
|
||||
return;
|
||||
|
||||
vpid = (int)_lwp_self();
|
||||
tmpbuf = linebuf[vpid].buf;
|
||||
len = linebuf[vpid].len;
|
||||
|
||||
if (len == 0)
|
||||
len += sprintf(tmpbuf, "[%05d.%05d]", getpid(), vpid);
|
||||
|
||||
va_start(ap, fmt);
|
||||
len += vsnprintf(tmpbuf + len, (unsigned int)(MAXLINELEN - len),
|
||||
fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
linebuf[vpid].len = len;
|
||||
|
||||
if (tmpbuf[len - 1] != '\n')
|
||||
return;
|
||||
|
||||
r = debugbuf->msg_bufr;
|
||||
w = debugbuf->msg_bufw;
|
||||
s = debugbuf->msg_bufs;
|
||||
diff1 = (long)w - (long)r;
|
||||
|
||||
if (w + len >= s) {
|
||||
cplen = s - w;
|
||||
debugbuf->msg_bufw = len - cplen;
|
||||
(void)memcpy(&debugbuf->msg_bufc[w],
|
||||
tmpbuf, cplen);
|
||||
(void)memcpy(&debugbuf->msg_bufc[0], tmpbuf + cplen,
|
||||
len - cplen);
|
||||
w = len - cplen;
|
||||
|
||||
/* Check for lapping the read pointer. */
|
||||
diff2 = (long)w - (long)r;
|
||||
if (((diff1 < 0) && (diff2 <= 0)) ||
|
||||
((diff1 > 0) && (diff2 >= 0)))
|
||||
debugbuf->msg_bufr = (w + 1) % s;
|
||||
} else {
|
||||
debugbuf->msg_bufw = w + len;
|
||||
(void)memcpy(&debugbuf->msg_bufc[w],
|
||||
tmpbuf, len);
|
||||
w += len;
|
||||
|
||||
/* Check for lapping the read pointer. */
|
||||
diff2 = (long)w - (long)r;
|
||||
if ((diff1 < 0) && (diff2 >= 0))
|
||||
debugbuf->msg_bufr = (w + 1) % s;
|
||||
}
|
||||
|
||||
linebuf[vpid].len = 0;
|
||||
}
|
||||
|
||||
int
|
||||
pthread__debuglog_newline(void)
|
||||
{
|
||||
int vpid;
|
||||
|
||||
if (debugbuf == NULL)
|
||||
return 1;
|
||||
|
||||
vpid = (int)_lwp_self();
|
||||
return (linebuf[vpid].len == 0);
|
||||
}
|
||||
|
||||
#else /* PTHREAD__DEBUG */
|
||||
|
||||
void
|
||||
pthread__debug_init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif /* PTHREAD__DEBUG */
|
@ -1,107 +0,0 @@
|
||||
/* $NetBSD: pthread_debug.h,v 1.12 2007/09/24 13:56:42 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Nathan J. Williams.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LIB_PTHREAD_DEBUG_H
|
||||
#define _LIB_PTHREAD_DEBUG_H
|
||||
|
||||
#define PTHREADD_CREATE 0
|
||||
#define PTHREADD_SPINLOCKS 1
|
||||
#define PTHREADD_SPINUNLOCKS 2
|
||||
#define PTHREADD_MUTEX_LOCK 3
|
||||
#define PTHREADD_MUTEX_LOCK_SLOW 4
|
||||
#define PTHREADD_MUTEX_TRYLOCK 5
|
||||
#define PTHREADD_MUTEX_UNLOCK 6
|
||||
#define PTHREADD_COND_WAIT 7
|
||||
#define PTHREADD_COND_TIMEDWAIT 8
|
||||
#define PTHREADD_COND_SIGNAL 9
|
||||
#define PTHREADD_COND_BROADCAST 10
|
||||
#define PTHREADD_COND_WOKEUP 11
|
||||
#define PTHREADD_NCOUNTERS 12
|
||||
|
||||
#define PTHREADD_INITCOUNTERNAMES { \
|
||||
"pthread_create()", /* 0 CREATE */ \
|
||||
"spinlock", /* 1 SPINLOCKS */ \
|
||||
"spinunlock", /* 2 SPINUNLOCKS */ \
|
||||
"mutex lock", /* 3 MUTEX_LOCK */ \
|
||||
"mutex lock (slow)", /* 4 MUTEX_LOCK_SLOW */ \
|
||||
"mutex trylock", /* 5 MUTEX_TRYLOCK */ \
|
||||
"mutex unlock", /* 6 MUTEX_UNLOCK */ \
|
||||
"cond wait", /* 7 COND_WAIT */ \
|
||||
"cond timedwait", /* 8 COND_TIMEDWAIT */ \
|
||||
"cond broadcast", /* 9 COND_BROADCAST */ \
|
||||
"cond signal", /* 10 COND_SIGNAL */ \
|
||||
"cond wokeup", /* 11 COND_WOKEUP */ \
|
||||
}
|
||||
|
||||
#define PTHREAD__DEBUG_SHMKEY (0x000f)
|
||||
#define PTHREAD__DEBUG_SHMSIZE (1<<18)
|
||||
|
||||
struct pthread_msgbuf {
|
||||
#define BUF_MAGIC 0x090976
|
||||
int msg_magic;
|
||||
size_t msg_bufw;
|
||||
size_t msg_bufr;
|
||||
size_t msg_bufs;
|
||||
char msg_bufc[1];
|
||||
};
|
||||
|
||||
void pthread__debug_init(void);
|
||||
struct pthread_msgbuf *pthread__debuglog_init(int);
|
||||
void pthread__debuglog_printf(const char *, ...);
|
||||
int pthread__debuglog_newline(void);
|
||||
|
||||
#ifdef PTHREAD__DEBUG
|
||||
|
||||
#undef PTHREAD_ALARM_DEBUG
|
||||
#define PTHREAD_MAIN_DEBUG
|
||||
|
||||
extern int pthread__debug_counters[PTHREADD_NCOUNTERS];
|
||||
|
||||
extern int pthread__dbg; /* Set by libpthread_dbg */
|
||||
|
||||
#define PTHREADD_ADD(x) (pthread__debug_counters[(x)]++)
|
||||
|
||||
#define DPRINTF(x) pthread__debuglog_printf x
|
||||
#else /* PTHREAD__DEBUG */
|
||||
|
||||
#define PTHREADD_ADD(x)
|
||||
#define DPRINTF(x)
|
||||
|
||||
#endif /* PTHREAD__DEBUG */
|
||||
|
||||
#endif /* _LIB_PTHREAD_DEBUG_H */
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pthread_int.h,v 1.61 2007/11/13 17:20:09 ad Exp $ */
|
||||
/* $NetBSD: pthread_int.h,v 1.62 2007/11/19 15:14:13 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001, 2002, 2003, 2006, 2007 The NetBSD Foundation, Inc.
|
||||
@ -49,7 +49,6 @@
|
||||
|
||||
#include "pthread_types.h"
|
||||
#include "pthread_queue.h"
|
||||
#include "pthread_debug.h"
|
||||
#include "pthread_md.h"
|
||||
|
||||
#include <sys/tree.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pthread_mutex.c,v 1.37 2007/11/13 15:57:11 ad Exp $ */
|
||||
/* $NetBSD: pthread_mutex.c,v 1.38 2007/11/19 15:14:13 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001, 2003, 2006, 2007 The NetBSD Foundation, Inc.
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: pthread_mutex.c,v 1.37 2007/11/13 15:57:11 ad Exp $");
|
||||
__RCSID("$NetBSD: pthread_mutex.c,v 1.38 2007/11/19 15:14:13 ad Exp $");
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
@ -155,8 +155,6 @@ pthread_mutex_lock(pthread_mutex_t *mutex)
|
||||
|
||||
self = pthread__self();
|
||||
|
||||
PTHREADD_ADD(PTHREADD_MUTEX_LOCK);
|
||||
|
||||
/*
|
||||
* Note that if we get the lock, we don't have to deal with any
|
||||
* non-default lock type handling.
|
||||
@ -187,7 +185,6 @@ pthread_mutex_lock_slow(pthread_t self, pthread_mutex_t *mutex)
|
||||
pthread__error(EINVAL, "Invalid mutex",
|
||||
mutex->ptm_magic == _PT_MUTEX_MAGIC);
|
||||
|
||||
PTHREADD_ADD(PTHREADD_MUTEX_LOCK_SLOW);
|
||||
for (;;) {
|
||||
/* Spin for a while. */
|
||||
count = pthread__nspins;
|
||||
@ -280,7 +277,6 @@ pthread_mutex_trylock(pthread_mutex_t *mutex)
|
||||
|
||||
self = pthread__self();
|
||||
|
||||
PTHREADD_ADD(PTHREADD_MUTEX_TRYLOCK);
|
||||
if (pthread__spintrylock(self, &mutex->ptm_lock) == 0) {
|
||||
/*
|
||||
* These tests can be performed without holding the
|
||||
@ -315,8 +311,6 @@ pthread_mutex_unlock(pthread_mutex_t *mutex)
|
||||
pthread__error(EINVAL, "Invalid mutex",
|
||||
mutex->ptm_magic == _PT_MUTEX_MAGIC);
|
||||
|
||||
PTHREADD_ADD(PTHREADD_MUTEX_UNLOCK);
|
||||
|
||||
/*
|
||||
* These tests can be performed without holding the
|
||||
* interlock because these fields are only modified
|
||||
|
Loading…
Reference in New Issue
Block a user