summaryrefslogtreecommitdiff
path: root/lib/isc/pthreads/mutex.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/isc/pthreads/mutex.c')
-rw-r--r--lib/isc/pthreads/mutex.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/isc/pthreads/mutex.c b/lib/isc/pthreads/mutex.c
index b57d9eee8daa..62ad540a7e17 100644
--- a/lib/isc/pthreads/mutex.c
+++ b/lib/isc/pthreads/mutex.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2004, 2005, 2007, 2008, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000-2002 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: mutex.c,v 1.16 2008/04/04 23:47:01 tbox Exp $ */
+/* $Id: mutex.c,v 1.18 2011/01/04 23:47:14 tbox Exp $ */
/*! \file */
@@ -30,6 +30,15 @@
#include <isc/util.h>
#include <isc/strerror.h>
+#if HAVE_PTHREADS < 5 /* HP-UX 10.20 has 4, needs this */
+# define pthread_mutex_init(m, a) \
+ pthread_mutex_init(m, (a) \
+ ? *(const pthread_mutexattr_t *)(a) \
+ : pthread_mutexattr_default)
+# define PTHREAD_MUTEX_RECURSIVE MUTEX_RECURSIVE_NP
+# define pthread_mutexattr_settype pthread_mutexattr_setkind_np
+#endif
+
#if ISC_MUTEX_PROFILE
/*@{*/
@@ -78,7 +87,7 @@ struct isc_mutexstats {
};
#ifndef ISC_MUTEX_PROFTABLESIZE
-#define ISC_MUTEX_PROFTABLESIZE (16 * 1024)
+#define ISC_MUTEX_PROFTABLESIZE (1024 * 1024)
#endif
static isc_mutexstats_t stats[ISC_MUTEX_PROFTABLESIZE];
static int stats_next = 0;
@@ -200,24 +209,24 @@ isc_mutex_statsprofile(FILE *fp) {
fprintf(fp, "Mutex stats (in us)\n");
for (i = 0; i < stats_next; i++) {
- fprintf(fp, "%-12s %4d: %10u %lu.%06lu %lu.%06lu\n",
+ fprintf(fp, "%-12s %4d: %10u %lu.%06lu %lu.%06lu %5d\n",
stats[i].file, stats[i].line, stats[i].count,
stats[i].locked_total.tv_sec,
stats[i].locked_total.tv_usec,
stats[i].wait_total.tv_sec,
- stats[i].wait_total.tv_usec
- );
+ stats[i].wait_total.tv_usec,
+ i);
for (j = 0; j < ISC_MUTEX_MAX_LOCKERS; j++) {
locker = &stats[i].lockers[j];
if (locker->file == NULL)
continue;
- fprintf(fp, " %-11s %4d: %10u %lu.%06lu %lu.%06lu\n",
+ fprintf(fp, " %-11s %4d: %10u %lu.%06lu %lu.%06lu %5d\n",
locker->file, locker->line, locker->count,
locker->locked_total.tv_sec,
locker->locked_total.tv_usec,
locker->wait_total.tv_sec,
- locker->wait_total.tv_usec
- );
+ locker->wait_total.tv_usec,
+ i);
}
}
}
@@ -234,10 +243,13 @@ isc_mutex_init_errcheck(isc_mutex_t *mp)
if (pthread_mutexattr_init(&attr) != 0)
return (ISC_R_UNEXPECTED);
- if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK) != 0)
+ if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK) != 0) {
+ pthread_mutexattr_destroy(&attr);
return (ISC_R_UNEXPECTED);
+ }
err = pthread_mutex_init(mp, &attr) != 0)
+ pthread_mutexattr_destroy(&attr);
if (err == ENOMEM)
return (ISC_R_NOMEMORY);
return ((err == 0) ? ISC_R_SUCCESS : ISC_R_UNEXPECTED);