#define WARN(var, msg) (warn (__FILE__, __LINE__, (msg), #var, (var)))
-#define ERROR(var,msg) (error(__FILE__, __LINE__, (msg), #var, (var)))
#define WARN_IF(rc, msg) {if (rc) warn (__FILE__, __LINE__, (msg), #rc, (rc));}
-#define ERROR_IF(rc,msg) {if (rc) error(__FILE__, __LINE__, (msg), #rc, (rc));}
+#define ERROR(var, msg) \
+ {if (!noerror) error(__FILE__, __LINE__, (msg), #var, (var));}
+#define ERROR_IF(rc, msg) \
+ {if (!noerror && (rc)) error(__FILE__, __LINE__, (msg), #rc, (rc));}
#if 0
static void
static void
error( const char *file, int line, const char *msg, const char *var, int val )
{
- if( !noerror ) {
- fprintf( stderr, "%s:%d: %s error: %s is %d\n",
- file, line, msg, var, val );
- if( !noabort )
- abort();
- }
+ fprintf( stderr, "%s:%d: %s error: %s is %d\n",
+ file, line, msg, var, val );
+ if( !noabort )
+ abort();
}
static void
#define WRAPPED(ptr) (ptr)
#define SET_OWNER(ptr) ((void) 0)
#define RESET_OWNER(ptr) ((void) 0)
-#define ASSERT_OWNER(ptr) ((void) 0)
-#define ASSERT_NO_OWNER(ptr) ((void) 0)
+#define ASSERT_OWNER(ptr, msg) ((void) 0)
+#define ASSERT_NO_OWNER(ptr, msg) ((void) 0)
#define alloc_usage(ptr, msg) ((void) 0)
#define check_usage(ptr, msg) ((void) 0)
static const ldap_int_thread_t ldap_debug_thread_none = LDAP_DEBUG_THREAD_NONE;
-int
-ldap_debug_thread_mutex_owner( ldap_pvt_thread_mutex_t *mutex )
+#define THREAD_MUTEX_OWNER(mutex) \
+ ldap_pvt_thread_equal( (mutex)->owner, ldap_pvt_thread_self() )
+
+void
+ldap_debug_thread_assert_mutex_owner(
+ const char *file,
+ int line,
+ const char *msg,
+ ldap_pvt_thread_mutex_t *mutex )
{
- return ldap_pvt_thread_equal( mutex->owner, ldap_pvt_thread_self() );
+ if( !(noerror || THREAD_MUTEX_OWNER( mutex )) )
+ error( file, line, "ASSERT_MUTEX_OWNER", msg, 0 );
}
#define WRAPPED(ptr) (&(ptr)->wrapped)
#define SET_OWNER(ptr) ((ptr)->owner = ldap_pvt_thread_self())
#define RESET_OWNER(ptr) ((ptr)->owner = ldap_debug_thread_none)
-#define ASSERT_OWNER LDAP_INT_THREAD_ASSERT_MUTEX_OWNER
+#define ASSERT_OWNER(ptr, msg) ERROR_IF( !THREAD_MUTEX_OWNER( ptr ), msg )
#ifndef ASSERT_NO_OWNER
-#define ASSERT_NO_OWNER(ptr) \
- assert( ldap_int_thread_equal( (ptr)->owner, ldap_debug_thread_none ) )
+#define ASSERT_NO_OWNER(ptr, msg) ERROR_IF( \
+ !ldap_int_thread_equal( (ptr)->owner, ldap_debug_thread_none ), msg )
#endif
#define INITED_VALUE 0x12345678UL
check_usage( &cond->usage, "ldap_pvt_thread_cond_wait:cond" );
check_usage( &mutex->usage, "ldap_pvt_thread_cond_wait:mutex" );
adjust_count( Idx_locked_mutex, -1 );
- ASSERT_OWNER( mutex );
+ ASSERT_OWNER( mutex, "ldap_pvt_thread_cond_wait" );
RESET_OWNER( mutex ); /* Breaks if this thread did not own the mutex */
rc = ldap_int_thread_cond_wait( WRAPPED( cond ), WRAPPED( mutex ) );
- ASSERT_NO_OWNER( mutex );
+ ASSERT_NO_OWNER( mutex, "ldap_pvt_thread_cond_wait" );
SET_OWNER( mutex );
adjust_count( Idx_locked_mutex, +1 );
ERROR_IF( rc, "ldap_pvt_thread_cond_wait" );
{
int rc;
check_usage( &mutex->usage, "ldap_pvt_thread_mutex_destroy" );
- ASSERT_NO_OWNER( mutex );
+ ASSERT_NO_OWNER( mutex, "ldap_pvt_thread_mutex_destroy" );
rc = ldap_int_thread_mutex_destroy( WRAPPED( mutex ) );
if( rc ) {
ERROR( rc, "ldap_pvt_thread_mutex_destroy" );
if( rc ) {
ERROR_IF( rc, "ldap_pvt_thread_mutex_lock" );
} else {
- ASSERT_NO_OWNER( mutex );
+ ASSERT_NO_OWNER( mutex, "ldap_pvt_thread_mutex_lock" );
SET_OWNER( mutex );
adjust_count( Idx_locked_mutex, +1 );
}
check_usage( &mutex->usage, "ldap_pvt_thread_mutex_trylock" );
rc = ldap_int_thread_mutex_trylock( WRAPPED( mutex ) );
if( rc == 0 ) {
- ASSERT_NO_OWNER( mutex );
+ ASSERT_NO_OWNER( mutex, "ldap_pvt_thread_mutex_trylock" );
SET_OWNER( mutex );
adjust_count( Idx_locked_mutex, +1 );
}
{
int rc;
check_usage( &mutex->usage, "ldap_pvt_thread_mutex_unlock" );
- ASSERT_OWNER( mutex );
+ ASSERT_OWNER( mutex, "ldap_pvt_thread_mutex_unlock" );
RESET_OWNER( mutex ); /* Breaks if this thread did not own the mutex */
rc = ldap_int_thread_mutex_unlock( WRAPPED( mutex ) );
if( rc ) {