* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: mutex.c,v 1.8.18.4 2005/07/12 01:22:32 marka Exp $ */
+/* $Id: mutex.c,v 1.8.18.5 2008/04/04 02:58:42 jinmei Exp $ */
/*! \file */
isc_mutexlocker_t lockers[ISC_MUTEX_MAX_LOCKERS];
};
-#define TABLESIZE (8 * 1024)
-static isc_mutexstats_t stats[TABLESIZE];
+#ifndef ISC_MUTEX_PROFTABLESIZE
+#define ISC_MUTEX_PROFTABLESIZE (16 * 1024)
+#endif
+static isc_mutexstats_t stats[ISC_MUTEX_PROFTABLESIZE];
+static int stats_next = 0;
static isc_boolean_t stats_init = ISC_FALSE;
static pthread_mutex_t statslock = PTHREAD_MUTEX_INITIALIZER;
RUNTIME_CHECK(pthread_mutex_lock(&statslock) == 0);
- if (stats_init == ISC_FALSE) {
- for (i = 0; i < TABLESIZE; i++) {
- stats[i].file = NULL;
- }
+ if (stats_init == ISC_FALSE)
stats_init = ISC_TRUE;
- }
- mp->stats = NULL;
- for (i = 0; i < TABLESIZE; i++) {
- if (stats[i].file == NULL) {
- mp->stats = &stats[i];
- break;
- }
- }
- RUNTIME_CHECK(mp->stats != NULL);
+ /*
+ * If all statistics entries have been used, give up and trigger an
+ * assertion failure. There would be no other way to deal with this
+ * because we'd like to keep record of all locks for the purpose of
+ * debugging and the number of necessary locks is unpredictable.
+ * If this failure is triggered while debugging, named should be
+ * rebuilt with an increased ISC_MUTEX_PROFTABLESIZE.
+ */
+ RUNTIME_CHECK(stats_next < ISC_MUTEX_PROFTABLESIZE);
+ mp->stats = &stats[stats_next++];
RUNTIME_CHECK(pthread_mutex_unlock(&statslock) == 0);
isc_mutex_statsprofile(FILE *fp) {
isc_mutexlocker_t *locker;
int i, j;
+
fprintf(fp, "Mutex stats (in us)\n");
- for (i = 0; i < TABLESIZE; i++) {
- if (stats[i].file == NULL)
- continue;
+ for (i = 0; i < stats_next; i++) {
fprintf(fp, "%-12s %4d: %10u %lu.%06lu %lu.%06lu\n",
stats[i].file, stats[i].line, stats[i].count,
stats[i].locked_total.tv_sec,
};
#endif
+#if !(ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK)) && !ISC_MUTEX_PROFILE
isc_result_t
isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) {
char strbuf[ISC_STRERRORSIZE];
}
return (result);
}
+#endif