mutex.c revision 8cbf3b6fc35091abde426930f2eadb8f53476c98
/*
* Copyright (C) 2004, 2005, 2007, 2008, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000-2002 Internet Software Consortium.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: mutex.c,v 1.18 2011/01/04 23:47:14 tbox Exp $ */
/*! \file */
#include <config.h>
#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <isc/strerror.h>
/*@{*/
do { \
} \
} while (0)
do { \
} \
} while (0)
/*@}*/
#define ISC_MUTEX_MAX_LOCKERS 32
typedef struct {
const char * file;
int line;
unsigned count;
struct timeval locked_total;
struct timeval wait_total;
struct isc_mutexstats {
const char * file; /*%< File mutex was created in. */
int line; /*%< Line mutex was created on. */
unsigned count;
struct timeval locked_total;
struct timeval wait_total;
};
#ifndef ISC_MUTEX_PROFTABLESIZE
#endif
static int stats_next = 0;
int i, err;
return (ISC_R_NOMEMORY);
if (err != 0)
return (ISC_R_UNEXPECTED);
if (stats_init == ISC_FALSE)
/*
* 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.
*/
for (i = 0; i < ISC_MUTEX_MAX_LOCKERS; i++) {
}
return (ISC_R_SUCCESS);
}
struct timeval postlock_t;
int i;
return (ISC_R_UNEXPECTED);
for (i = 0; i < ISC_MUTEX_MAX_LOCKERS; i++) {
break;
break;
}
}
}
return (ISC_R_SUCCESS);
}
}
}
void
int i, j;
for (i = 0; i < stats_next; i++) {
i);
for (j = 0; j < ISC_MUTEX_MAX_LOCKERS; j++) {
continue;
i);
}
}
}
#endif /* ISC_MUTEX_PROFILE */
#if ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK)
{
int err;
if (pthread_mutexattr_init(&attr) != 0)
return (ISC_R_UNEXPECTED);
return (ISC_R_UNEXPECTED);
}
return (ISC_R_NOMEMORY);
}
#endif
PTHREAD_MUTEX_ERRORCHECK, /* m_type */
0 /* m_flags, which appears to be unused. */
};
#endif
char strbuf[ISC_STRERRORSIZE];
int err;
if (pthread_mutexattr_init(&attr) != 0)
return (ISC_R_UNEXPECTED);
return (ISC_R_UNEXPECTED);
}
#else /* HAVE_PTHREAD_MUTEX_ADAPTIVE_NP */
#endif /* HAVE_PTHREAD_MUTEX_ADAPTIVE_NP */
return (ISC_R_NOMEMORY);
if (err != 0) {
strbuf);
}
return (result);
}
#endif