Add thread debugging wrapper thr_debug.c and ldap_thr_debug.h in libldap_r/,

enabled with LDAP_THREAD_DEBUG (cpp macro and environment variable):

Move any ldap_pvt_* definitions from ldap_int_thread.h to ldap_pvt_thread.h.
#define ldap_int_thread_equal/ldap_pvt_thread_equal instead of tpool.c:TID_EQ.
Define some ldap_debug_*_t types, and LDAP_UINTPTR_T, in ldap_int_thread.h.
ldap_int_thread.h/ldap_pvt_thread.h can now be included multiple times, giving
different results depending on whether libldap_r/ldap_thr_debug.h was included.
Add some cleanup and some preprocessor hacks.
#define LDAP_THREAD*_IMPLEMENTATION in libldap_r/*.c, used by ldap_thr_debug.h.
Add PTHREAD_MUTEX_ERRORCHECK/PTHREAD_MUTEX_ERRORCHECK_NP in thr_posix.c.
This commit is contained in:
Hallvard Furuseth 2005-09-17 23:28:08 +00:00
parent ad2ec8effa
commit 123948bd5e
15 changed files with 1371 additions and 42 deletions

View File

@ -14,6 +14,16 @@
* <http://www.OpenLDAP.org/license.html>.
*/
LDAP_BEGIN_DECL
/* Can be done twice in libldap_r. See libldap_r/ldap_thr_debug.h. */
LDAP_F(int) ldap_int_thread_initialize LDAP_P(( void ));
LDAP_F(int) ldap_int_thread_destroy LDAP_P(( void ));
LDAP_END_DECL
#ifndef _LDAP_INT_THREAD_H
#define _LDAP_INT_THREAD_H
@ -35,6 +45,8 @@ typedef pthread_t ldap_int_thread_t;
typedef pthread_mutex_t ldap_int_thread_mutex_t;
typedef pthread_cond_t ldap_int_thread_cond_t;
#define ldap_int_thread_equal(a, b) pthread_equal((a), (b))
#if defined( _POSIX_REENTRANT_FUNCTIONS ) || \
defined( _POSIX_THREAD_SAFE_FUNCTIONS ) || \
defined( _POSIX_THREADSAFE_FUNCTIONS )
@ -53,7 +65,7 @@ typedef pthread_cond_t ldap_int_thread_cond_t;
#if 0 && defined( HAVE_PTHREAD_RWLOCK_DESTROY )
#define LDAP_THREAD_HAVE_RDWR 1
typedef pthread_rwlock_t ldap_pvt_thread_rdwr_t;
typedef pthread_rwlock_t ldap_int_thread_rdwr_t;
#endif
LDAP_END_DECL
@ -97,7 +109,7 @@ typedef pth_cond_t ldap_int_thread_cond_t;
#if 0
#define LDAP_THREAD_HAVE_RDWR 1
typedef pth_rwlock_t ldap_pvt_thread_rdwr_t;
typedef pth_rwlock_t ldap_int_thread_rdwr_t;
#endif
LDAP_END_DECL
@ -155,6 +167,11 @@ typedef struct ldap_int_thread_lwp_cv ldap_int_thread_cond_t;
LDAP_END_DECL
#elif defined(HAVE_NT_THREADS)
/*************************************
* *
* thread definitions for NT threads *
* *
*************************************/
#include <process.h>
#include <windows.h>
@ -168,7 +185,6 @@ typedef HANDLE ldap_int_thread_cond_t;
LDAP_END_DECL
#else
/***********************************
* *
* thread definitions for no *
@ -193,10 +209,17 @@ LDAP_END_DECL
#endif /* no threads support */
LDAP_BEGIN_DECL
LDAP_F(int) ldap_int_thread_initialize LDAP_P(( void ));
LDAP_F(int) ldap_int_thread_destroy LDAP_P(( void ));
#ifndef ldap_int_thread_equal
#define ldap_int_thread_equal(a, b) ((a) == (b))
#endif
#ifndef LDAP_THREAD_HAVE_RDWR
typedef struct ldap_int_thread_rdwr_s * ldap_int_thread_rdwr_t;
#endif
LDAP_F(int) ldap_int_thread_pool_startup ( void );
LDAP_F(int) ldap_int_thread_pool_shutdown ( void );
@ -206,4 +229,46 @@ typedef struct ldap_int_thread_pool_s * ldap_int_thread_pool_t;
LDAP_END_DECL
#if defined(LDAP_THREAD_DEBUG) && !((LDAP_THREAD_DEBUG +0) & 2U)
#define LDAP_THREAD_DEBUG_WRAP 1
#endif
#ifdef LDAP_THREAD_DEBUG_WRAP
/**************************************
* *
* definitions for type-wrapped debug *
* *
**************************************/
LDAP_BEGIN_DECL
#ifndef LDAP_UINTPTR_T /* May be configured in CPPFLAGS */
#define LDAP_UINTPTR_T unsigned long
#endif
typedef union {
unsigned char *ptr;
LDAP_UINTPTR_T num;
} ldap_debug_usage_info_t;
typedef struct {
ldap_int_thread_mutex_t wrapped;
ldap_debug_usage_info_t usage;
} ldap_debug_thread_mutex_t;
typedef struct {
ldap_int_thread_cond_t wrapped;
ldap_debug_usage_info_t usage;
} ldap_debug_thread_cond_t;
typedef struct {
ldap_int_thread_rdwr_t wrapped;
ldap_debug_usage_info_t usage;
} ldap_debug_thread_rdwr_t;
LDAP_END_DECL
#endif /* LDAP_THREAD_DEBUG_WRAP */
#endif /* _LDAP_INT_THREAD_H */

View File

@ -15,16 +15,27 @@
*/
#ifndef _LDAP_PVT_THREAD_H
#define _LDAP_PVT_THREAD_H
#define _LDAP_PVT_THREAD_H /* libldap_r/ldap_thr_debug.h #undefines this */
#include "ldap_cdefs.h"
#include "ldap_int_thread.h"
LDAP_BEGIN_DECL
typedef ldap_int_thread_t ldap_pvt_thread_t;
typedef ldap_int_thread_mutex_t ldap_pvt_thread_mutex_t;
typedef ldap_int_thread_cond_t ldap_pvt_thread_cond_t;
#ifndef LDAP_PVT_THREAD_H_DONE
typedef ldap_int_thread_t ldap_pvt_thread_t;
#ifdef LDAP_THREAD_DEBUG_WRAP
typedef ldap_debug_thread_mutex_t ldap_pvt_thread_mutex_t;
typedef ldap_debug_thread_cond_t ldap_pvt_thread_cond_t;
typedef ldap_debug_thread_rdwr_t ldap_pvt_thread_rdwr_t;
#else
typedef ldap_int_thread_mutex_t ldap_pvt_thread_mutex_t;
typedef ldap_int_thread_cond_t ldap_pvt_thread_cond_t;
typedef ldap_int_thread_rdwr_t ldap_pvt_thread_rdwr_t;
#endif
#endif /* !LDAP_PVT_THREAD_H_DONE */
#define ldap_pvt_thread_equal ldap_int_thread_equal
LDAP_F( int )
ldap_pvt_thread_initialize LDAP_P(( void ));
@ -44,6 +55,7 @@ ldap_pvt_thread_set_concurrency LDAP_P(( int ));
#define LDAP_PVT_THREAD_CREATE_JOINABLE 0
#define LDAP_PVT_THREAD_CREATE_DETACHED 1
#ifndef LDAP_PVT_THREAD_H_DONE
#define LDAP_PVT_THREAD_SET_STACK_SIZE
#ifndef LDAP_PVT_THREAD_STACK_SIZE
/* LARGE stack. Will be twice as large on 64 bit machine. */
@ -52,6 +64,7 @@ ldap_pvt_thread_set_concurrency LDAP_P(( int ));
#elif LDAP_PVT_THREAD_STACK_SIZE == 0
#undef LDAP_PVT_THREAD_SET_STACK_SIZE
#endif
#endif /* !LDAP_PVT_THREAD_H_DONE */
LDAP_F( int )
ldap_pvt_thread_create LDAP_P((
@ -107,10 +120,6 @@ ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
LDAP_F( ldap_pvt_thread_t )
ldap_pvt_thread_self LDAP_P(( void ));
#ifndef LDAP_THREAD_HAVE_RDWR
typedef struct ldap_int_thread_rdwr_s * ldap_pvt_thread_rdwr_t;
#endif
LDAP_F( int )
ldap_pvt_thread_rdwr_init LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
@ -149,10 +158,12 @@ ldap_pvt_thread_rdwr_active LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
#define LDAP_PVT_THREAD_EINVAL EINVAL
#define LDAP_PVT_THREAD_EBUSY EINVAL
#ifndef LDAP_PVT_THREAD_H_DONE
typedef ldap_int_thread_pool_t ldap_pvt_thread_pool_t;
typedef void * (ldap_pvt_thread_start_t) LDAP_P((void *ctx, void *arg));
typedef void (ldap_pvt_thread_pool_keyfree_t) LDAP_P((void *key, void *data));
#endif /* !LDAP_PVT_THREAD_H_DONE */
LDAP_F( int )
ldap_pvt_thread_pool_init LDAP_P((
@ -213,4 +224,5 @@ ldap_pvt_thread_pool_context_reset LDAP_P(( void *key ));
LDAP_END_DECL
#define LDAP_PVT_THREAD_H_DONE
#endif /* _LDAP_THREAD_H */

View File

@ -31,10 +31,10 @@ XXSRCS = apitest.c test.c \
turn.c groupings.c txn.c ppolicy.c
SRCS = threads.c rdwr.c tpool.c rq.c \
thr_posix.c thr_cthreads.c thr_thr.c thr_lwp.c thr_nt.c \
thr_pth.c thr_stub.c
thr_pth.c thr_stub.c thr_debug.c
OBJS = threads.lo rdwr.lo tpool.lo rq.lo \
thr_posix.lo thr_cthreads.lo thr_thr.lo thr_lwp.lo thr_nt.lo \
thr_pth.lo thr_stub.lo \
thr_pth.lo thr_stub.lo thr_debug.lo \
bind.lo open.lo result.lo error.lo compare.lo search.lo \
controls.lo messages.lo references.lo extended.lo cyrus.lo \
modify.lo add.lo modrdn.lo delete.lo abandon.lo \

View File

@ -0,0 +1,175 @@
/* ldap_thr_debug.h - preprocessor magic for LDAP_THREAD_DEBUG */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2005 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
#ifdef LDAP_THREAD_DEBUG
/*
* libldap_r .c files should include this file after ldap_pvt_thread.h,
* with the appropriate LDAP_THREAD*_IMPLEMENTATION macro defined.
*/
#ifndef _LDAP_PVT_THREAD_H
#error "ldap_pvt_thread.h" must be included before "ldap_thr_debug.h"
#endif
/*
* Support for thr_debug.c:
*
* thr_debug.c defines the ldap_pvt_*() as wrappers around
* ldap_int_*(), and ldap_debug_*() around ldap_int_*().
*
* Renames ldap_pvt_thread_* names to ldap_int_thread_*, and a few
* ldap_int_*() names to ldap_debug_*(). Includes "ldap_pvt_thread.h"
* to declare these renamed functions, and undefines the macros
* afterwards when included from thr_debug.c. So,
*
* libldap_r/<not thr_debug.c> define ldap_int_* instead of ldap_pvt_*.
* In thread.c, ldap_pvt_thread_<initialize/destroy>() will call
* ldap_debug_*() instead of ldap_int_*().
* In tpool.c, ldap_int_thread_pool_shutdown() has thr_debug support
* which treats ldap_pvt_thread_pool_destroy() the same way.
*/
#ifndef LDAP_THREAD_IMPLEMENTATION /* for first part of threads.c */
#define ldap_int_thread_initialize ldap_debug_thread_initialize
#define ldap_int_thread_destroy ldap_debug_thread_destroy
#else /* LDAP_THREAD_IMPLEMENTATION -- for thr_*.c and end of threads.c */
#undef ldap_int_thread_initialize
#undef ldap_int_thread_destroy
#ifdef LDAP_THREAD_DEBUG_WRAP /* see ldap_pvt_thread.h */
#define ldap_pvt_thread_mutex_t ldap_int_thread_mutex_t
#define ldap_pvt_thread_cond_t ldap_int_thread_cond_t
#endif
#define ldap_pvt_thread_sleep ldap_int_thread_sleep
#define ldap_pvt_thread_get_concurrency ldap_int_thread_get_concurrency
#define ldap_pvt_thread_set_concurrency ldap_int_thread_set_concurrency
#define ldap_pvt_thread_create ldap_int_thread_create
#define ldap_pvt_thread_exit ldap_int_thread_exit
#define ldap_pvt_thread_join ldap_int_thread_join
#define ldap_pvt_thread_kill ldap_int_thread_kill
#define ldap_pvt_thread_yield ldap_int_thread_yield
#define ldap_pvt_thread_cond_init ldap_int_thread_cond_init
#define ldap_pvt_thread_cond_destroy ldap_int_thread_cond_destroy
#define ldap_pvt_thread_cond_signal ldap_int_thread_cond_signal
#define ldap_pvt_thread_cond_broadcast ldap_int_thread_cond_broadcast
#define ldap_pvt_thread_cond_wait ldap_int_thread_cond_wait
#define ldap_pvt_thread_mutex_init ldap_int_thread_mutex_init
#define ldap_pvt_thread_mutex_destroy ldap_int_thread_mutex_destroy
#define ldap_pvt_thread_mutex_lock ldap_int_thread_mutex_lock
#define ldap_pvt_thread_mutex_trylock ldap_int_thread_mutex_trylock
#define ldap_pvt_thread_mutex_unlock ldap_int_thread_mutex_unlock
#define ldap_pvt_thread_self ldap_int_thread_self
#endif /* LDAP_THREAD_IMPLEMENTATION */
#ifdef LDAP_THREAD_RDWR_IMPLEMENTATION /* rdwr.c, thr_debug.c */
#ifdef LDAP_THREAD_DEBUG_WRAP /* see ldap_pvt_thread.h */
#define ldap_pvt_thread_rdwr_t ldap_int_thread_rdwr_t
#endif
#define ldap_pvt_thread_rdwr_init ldap_int_thread_rdwr_init
#define ldap_pvt_thread_rdwr_destroy ldap_int_thread_rdwr_destroy
#define ldap_pvt_thread_rdwr_rlock ldap_int_thread_rdwr_rlock
#define ldap_pvt_thread_rdwr_rtrylock ldap_int_thread_rdwr_rtrylock
#define ldap_pvt_thread_rdwr_runlock ldap_int_thread_rdwr_runlock
#define ldap_pvt_thread_rdwr_wlock ldap_int_thread_rdwr_wlock
#define ldap_pvt_thread_rdwr_wtrylock ldap_int_thread_rdwr_wtrylock
#define ldap_pvt_thread_rdwr_wunlock ldap_int_thread_rdwr_wunlock
#define ldap_pvt_thread_rdwr_readers ldap_int_thread_rdwr_readers
#define ldap_pvt_thread_rdwr_writers ldap_int_thread_rdwr_writers
#define ldap_pvt_thread_rdwr_active ldap_int_thread_rdwr_active
#endif /* LDAP_THREAD_RDWR_IMPLEMENTATION */
#ifdef LDAP_THREAD_POOL_IMPLEMENTATION /* tpool.c, thr_stub.c, thr_debug.c */
#ifdef LDAP_THREAD_DEBUG_WRAP /* see ldap_pvt_thread.h */
#define ldap_pvt_thread_pool_t ldap_int_thread_pool_t
#endif
#define ldap_pvt_thread_pool_init ldap_int_thread_pool_init
#define ldap_pvt_thread_pool_submit ldap_int_thread_pool_submit
#define ldap_pvt_thread_pool_maxthreads ldap_int_thread_pool_maxthreads
#define ldap_pvt_thread_pool_backload ldap_int_thread_pool_backload
#define ldap_pvt_thread_pool_pause ldap_int_thread_pool_pause
#define ldap_pvt_thread_pool_resume ldap_int_thread_pool_resume
#define ldap_pvt_thread_pool_destroy ldap_int_thread_pool_destroy
#define ldap_pvt_thread_pool_getkey ldap_int_thread_pool_getkey
#define ldap_pvt_thread_pool_setkey ldap_int_thread_pool_setkey
#define ldap_pvt_thread_pool_purgekey ldap_int_thread_pool_purgekey
#define ldap_pvt_thread_pool_context ldap_int_thread_pool_context
#define ldap_pvt_thread_pool_context_reset ldap_int_thread_pool_context_reset
#endif /* LDAP_THREAD_POOL_IMPLEMENTATION */
#undef _LDAP_PVT_THREAD_H
#include "ldap_pvt_thread.h"
#ifdef LDAP_THREAD_POOL_IMPLEMENTATION /* tpool.c */
/*
* tpool.c:ldap_int_thread_pool_shutdown() needs this. Could not
* use it for ldap_pvt_thread.h above because of its use of LDAP_P().
*/
#undef ldap_pvt_thread_pool_destroy
#define ldap_pvt_thread_pool_destroy(p,r) ldap_int_thread_pool_destroy(p,r)
#endif
#ifdef LDAP_THREAD_DEBUG_IMPLEMENTATION /* thr_debug.c */
#undef ldap_pvt_thread_mutex_t
#undef ldap_pvt_thread_cond_t
#undef ldap_pvt_thread_sleep
#undef ldap_pvt_thread_get_concurrency
#undef ldap_pvt_thread_set_concurrency
#undef ldap_pvt_thread_create
#undef ldap_pvt_thread_exit
#undef ldap_pvt_thread_join
#undef ldap_pvt_thread_kill
#undef ldap_pvt_thread_yield
#undef ldap_pvt_thread_cond_init
#undef ldap_pvt_thread_cond_destroy
#undef ldap_pvt_thread_cond_signal
#undef ldap_pvt_thread_cond_broadcast
#undef ldap_pvt_thread_cond_wait
#undef ldap_pvt_thread_mutex_init
#undef ldap_pvt_thread_mutex_destroy
#undef ldap_pvt_thread_mutex_lock
#undef ldap_pvt_thread_mutex_trylock
#undef ldap_pvt_thread_mutex_unlock
#undef ldap_pvt_thread_self
/* LDAP_THREAD_RDWR_IMPLEMENTATION: */
#undef ldap_pvt_thread_rdwr_t
#undef ldap_pvt_thread_rdwr_init
#undef ldap_pvt_thread_rdwr_destroy
#undef ldap_pvt_thread_rdwr_rlock
#undef ldap_pvt_thread_rdwr_rtrylock
#undef ldap_pvt_thread_rdwr_runlock
#undef ldap_pvt_thread_rdwr_wlock
#undef ldap_pvt_thread_rdwr_wtrylock
#undef ldap_pvt_thread_rdwr_wunlock
#undef ldap_pvt_thread_rdwr_readers
#undef ldap_pvt_thread_rdwr_writers
#undef ldap_pvt_thread_rdwr_active
/* LDAP_THREAD_POOL_IMPLEMENTATION: */
#undef ldap_pvt_thread_pool_t
#undef ldap_pvt_thread_pool_init
#undef ldap_pvt_thread_pool_submit
#undef ldap_pvt_thread_pool_maxthreads
#undef ldap_pvt_thread_pool_backload
#undef ldap_pvt_thread_pool_pause
#undef ldap_pvt_thread_pool_resume
#undef ldap_pvt_thread_pool_destroy
#undef ldap_pvt_thread_pool_getkey
#undef ldap_pvt_thread_pool_setkey
#undef ldap_pvt_thread_pool_purgekey
#undef ldap_pvt_thread_pool_context
#undef ldap_pvt_thread_pool_context_reset
#endif /* LDAP_THREAD_DEBUG_IMPLEMENTATION */
#endif /* LDAP_THREAD_DEBUG */

View File

@ -40,7 +40,9 @@
#include <ac/time.h>
#include "ldap-int.h"
#include "ldap_pvt_thread.h"
#include "ldap_pvt_thread.h" /* Get the thread interface */
#define LDAP_THREAD_RDWR_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
/*
* implementations that provide their own compatible
@ -439,6 +441,6 @@ int ldap_pvt_thread_rdwr_active(ldap_pvt_thread_rdwr_t *rwlock)
ldap_pvt_thread_rdwr_writers(rwlock));
}
#endif /* LDAP_DEBUG */
#endif /* LDAP_RDWR_DEBUG */
#endif /* LDAP_THREAD_HAVE_RDWR */

View File

@ -20,7 +20,9 @@
#include "portable.h"
#if defined( HAVE_MACH_CTHREADS )
#include "ldap_pvt_thread.h"
#include "ldap_pvt_thread.h" /* Get the thread interface */
#define LDAP_THREAD_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
int
ldap_int_thread_initialize( void )

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,9 @@
#include "ldap-int.h"
#include "ldap_pvt_thread.h"
#include "ldap_pvt_thread.h" /* Get the thread interface */
#define LDAP_THREAD_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
#include <lwp/lwp.h>
#include <lwp/stackdep.h>
@ -67,7 +69,7 @@ ldap_int_thread_initialize( void )
int
ldap_int_thread_destroy( void )
{
/* need to destory lwp_scheduler thread and clean up private
/* need to destroy lwp_scheduler thread and clean up private
variables */
return 0;
}
@ -311,7 +313,7 @@ ldap_pvt_thread_cond_signal( ldap_pvt_thread_cond_t *cond )
int
ldap_pvt_thread_cond_wait( ldap_pvt_thread_cond_t *cond,
ldap_int_thread_mutex_t *mutex )
ldap_pvt_thread_mutex_t *mutex )
{
if ( ! cond->lcv_created ) {
cv_create( &cond->lcv_cv, *mutex );

View File

@ -18,7 +18,9 @@
#if defined( HAVE_NT_THREADS )
#include "ldap_pvt_thread.h"
#include "ldap_pvt_thread.h" /* Get the thread interface */
#define LDAP_THREAD_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
typedef struct ldap_int_thread_s {
long tid;

View File

@ -20,8 +20,10 @@
#include <ac/errno.h>
#include "ldap_pvt_thread.h"
#include "ldap_pvt_thread.h" /* Get the thread interface */
#define LDAP_THREAD_IMPLEMENTATION
#define LDAP_THREAD_RDWR_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
#if HAVE_PTHREADS < 6
# define LDAP_INT_THREAD_ATTR_DEFAULT pthread_attr_default
@ -30,13 +32,29 @@
#else
# define LDAP_INT_THREAD_ATTR_DEFAULT NULL
# define LDAP_INT_THREAD_CONDATTR_DEFAULT NULL
# define LDAP_INT_THREAD_MUTEXATTR_DEFAULT NULL
# define LDAP_INT_THREAD_MUTEXATTR_DEFAULT NULL
#endif
#ifdef LDAP_THREAD_DEBUG
# if defined LDAP_INT_THREAD_MUTEXATTR /* May be defined in CPPFLAGS */
# elif defined HAVE_PTHREAD_KILL_OTHER_THREADS_NP
/* LinuxThreads hack */
# define LDAP_INT_THREAD_MUTEXATTR PTHREAD_MUTEX_ERRORCHECK_NP
# else
# define LDAP_INT_THREAD_MUTEXATTR PTHREAD_MUTEX_ERRORCHECK
# endif
static pthread_mutexattr_t mutex_attr;
# undef LDAP_INT_THREAD_MUTEXATTR_DEFAULT
# define LDAP_INT_THREAD_MUTEXATTR_DEFAULT &mutex_attr
#endif
int
ldap_int_thread_initialize( void )
{
#ifdef LDAP_INT_THREAD_MUTEXATTR
pthread_mutexattr_init( &mutex_attr );
pthread_mutexattr_settype( &mutex_attr, LDAP_INT_THREAD_MUTEXATTR );
#endif
return 0;
}
@ -46,6 +64,9 @@ ldap_int_thread_destroy( void )
#ifdef HAVE_PTHREAD_KILL_OTHER_THREADS_NP
/* LinuxThreads: kill clones */
pthread_kill_other_threads_np();
#endif
#ifdef LDAP_INT_THREAD_MUTEXATTR
pthread_mutexattr_destroy( &mutex_attr );
#endif
return 0;
}
@ -407,7 +428,7 @@ int ldap_pvt_thread_rdwr_wunlock( ldap_pvt_thread_rdwr_t *rw )
#endif
}
#endif /* HAVE_PTHREAD_RDLOCK_DESTROY */
#endif /* HAVE_PTHREAD_RWLOCK_DESTROY */
#endif /* LDAP_THREAD_HAVE_RDWR */
#endif /* HAVE_PTHREADS */

View File

@ -18,7 +18,11 @@
#if defined( HAVE_GNU_PTH )
#include "ldap_pvt_thread.h"
#include "ldap_pvt_thread.h" /* Get the thread interface */
#define LDAP_THREAD_IMPLEMENTATION
#define LDAP_THREAD_RDWR_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
#include <errno.h>
/*******************

View File

@ -18,7 +18,10 @@
#if defined( NO_THREADS )
#include "ldap_pvt_thread.h"
#include "ldap_pvt_thread.h" /* Get the thread interface */
#define LDAP_THREAD_IMPLEMENTATION
#define LDAP_THREAD_POOL_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
/***********************************************************************
* *

View File

@ -18,7 +18,9 @@
#if defined( HAVE_THR )
#include "ldap_pvt_thread.h"
#include "ldap_pvt_thread.h" /* Get the thread interface */
#define LDAP_THREAD_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
/*******************
* *

View File

@ -22,7 +22,8 @@
#include <ac/string.h>
#include <ac/unistd.h>
#include "ldap_pvt_thread.h"
#include "ldap_pvt_thread.h" /* Get the thread interface */
#include "ldap_thr_debug.h" /* May redirect thread initialize/destroy calls */
/*
@ -60,6 +61,15 @@ int ldap_pvt_thread_destroy( void )
return ldap_int_thread_destroy();
}
/*
* Default implementations of some LDAP thread routines
*/
#define LDAP_THREAD_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename the symbols defined below */
#ifndef LDAP_THREAD_HAVE_GETCONCURRENCY
int
ldap_pvt_thread_get_concurrency ( void )

View File

@ -24,8 +24,10 @@
#include <ac/errno.h>
#include "ldap-int.h"
#include "ldap_pvt_thread.h"
#include "ldap_pvt_thread.h" /* Get the thread interface */
#include "ldap_queue.h"
#define LDAP_THREAD_POOL_IMPLEMENTATION
#include "ldap_thr_debug.h" /* May rename symbols defined below */
#ifndef LDAP_THREAD_HAVE_TPOOL
@ -50,11 +52,6 @@ typedef struct ldap_int_thread_key_s {
static ldap_pvt_thread_t tid_zero;
#ifdef HAVE_PTHREADS
#define TID_EQ(a,b) pthread_equal((a),(b))
#else
#define TID_EQ(a,b) ((a) == (b))
#endif
static struct {
ldap_pvt_thread_t id;
ldap_int_thread_key_t *ctx;
@ -115,7 +112,7 @@ ldap_int_thread_pool_shutdown ( void )
while ((pool = LDAP_STAILQ_FIRST(&ldap_int_thread_pool_list)) != NULL) {
LDAP_STAILQ_REMOVE_HEAD(&ldap_int_thread_pool_list, ltp_next);
ldap_pvt_thread_pool_destroy( &pool, 0);
(ldap_pvt_thread_pool_destroy)(&pool, 0); /* ignore thr_debug macro */
}
ldap_pvt_thread_mutex_destroy(&ldap_pvt_thread_pool_mutex);
return(0);
@ -277,7 +274,7 @@ ldap_pvt_thread_pool_submit (
*/
TID_HASH(thr, hash);
for (rc = hash & (LDAP_MAXTHR-1);
!TID_EQ(thread_keys[rc].id, tid_zero);
!ldap_pvt_thread_equal(thread_keys[rc].id, tid_zero);
rc = (rc+1) & (LDAP_MAXTHR-1));
thread_keys[rc].id = thr;
} else {
@ -437,7 +434,8 @@ ldap_int_thread_pool_wrapper (
/* store pointer to our keys */
TID_HASH(tid, hash);
for (i = hash & (LDAP_MAXTHR-1); !TID_EQ(thread_keys[i].id, tid);
for (i = hash & (LDAP_MAXTHR-1);
!ldap_pvt_thread_equal(thread_keys[i].id, tid);
i = (i+1) & (LDAP_MAXTHR-1));
thread_keys[i].ctx = ltc_key;
keyslot = i;
@ -661,12 +659,14 @@ void *ldap_pvt_thread_pool_context( )
int i, hash;
tid = ldap_pvt_thread_self();
if ( TID_EQ( tid, ldap_int_main_tid ))
if ( ldap_pvt_thread_equal( tid, ldap_int_main_tid ))
return ldap_int_main_thrctx;
TID_HASH( tid, hash );
for (i = hash & (LDAP_MAXTHR-1); !TID_EQ(thread_keys[i].id, tid_zero) &&
!TID_EQ(thread_keys[i].id, tid); i = (i+1) & (LDAP_MAXTHR-1));
for (i = hash & (LDAP_MAXTHR-1);
!ldap_pvt_thread_equal(thread_keys[i].id, tid_zero) &&
!ldap_pvt_thread_equal(thread_keys[i].id, tid);
i = (i+1) & (LDAP_MAXTHR-1));
return thread_keys[i].ctx;
}