#!/bin/sh -x : Script which unwraps the Posix thread wrapper : Wrap function definitions and declarations in parens to override macros perl -i~ -p0777e 's/^(int|void|ldap_pvt_thread_t)\s+(ldap_pvt_t\w+)/$1\n($2)/gm' libraries/libldap_r/thr_posix.c perl -i~ -p0777e 's/^(ldap_pvt_thread_(?!pool|rmutex)\w+)(?= LDAP_P\b)/($1)/gm' include/ldap_pvt_thread.h : Unwrap common usage of thread functions patch -p0 <<'EOP' --- include/ldap_int_thread.h~ 2009-04-06 17:26:35 +++ include/ldap_int_thread.h 2009-07-30 14:23:43 @@ -69,6 +69,51 @@ typedef pthread_rwlock_t ldap_int_thread_rdwr_t; #endif +/* Unwrap most of the pthread wrapper if feasible */ +#if (HAVE_PTHREADS) >= 7 && !defined(LDAP_THREAD_DEBUG) +#ifdef HAVE_PTHREAD_SETCONCURRENCY +# define ldap_pvt_thread_set_concurrency(n) pthread_setconcurrency(n) +#endif +#ifdef HAVE_PTHREAD_GETCONCURRENCY +# define ldap_pvt_thread_get_concurrency() pthread_getconcurrency() +#endif +#define ldap_pvt_thread_exit(retval) pthread_exit(retval) +#define ldap_pvt_thread_join(thr, retval) pthread_join(thr, retval) +#if 0 && defined(HAVE_PTHREAD_KILL) /* would need */ +# define ldap_pvt_thread_kill(thr, signo) pthread_kill(thr, signo) +#endif +#if !defined(REPLACE_BROKEN_YIELD) && !defined(HAVE_THR_YIELD) && \ + (HAVE_PTHREADS) == 10 +# define ldap_pvt_thread_yield() sched_yield() +#endif +#define ldap_pvt_thread_cond_init(cnd) pthread_cond_init(cnd, NULL) +#define ldap_pvt_thread_cond_destroy(cnd) pthread_cond_destroy(cnd) +#define ldap_pvt_thread_cond_signal(cnd) pthread_cond_signal(cnd) +#define ldap_pvt_thread_cond_broadcast(cnd) pthread_cond_broadcast(cnd) +#define ldap_pvt_thread_cond_wait(cnd, mtx) pthread_cond_wait(cnd, mtx) +#define ldap_pvt_thread_mutex_init(mtx) pthread_mutex_init(mtx, NULL) +#define ldap_pvt_thread_mutex_destroy(mtx) pthread_mutex_destroy(mtx) +#define ldap_pvt_thread_mutex_lock(mtx) pthread_mutex_lock(mtx) +#define ldap_pvt_thread_mutex_trylock(mtx) pthread_mutex_trylock(mtx) +#define ldap_pvt_thread_mutex_unlock(mtx) pthread_mutex_unlock(mtx) +#define ldap_pvt_thread_self() pthread_self() +#define ldap_pvt_thread_key_create(key) pthread_key_create(key, NULL) +#define ldap_pvt_thread_key_destroy(key) pthread_key_delete(key) +#define ldap_pvt_thread_key_setdata(key, d) pthread_setspecific(key, d) +#define ldap_pvt_thread_key_getdata(key, d) \ + ((void) (*(d) = pthread_getspecific(key)), 0) +#if defined(LDAP_THREAD_HAVE_RDWR) && defined(HAVE_PTHREAD_RWLOCK_DESTROY) +# define ldap_pvt_thread_rdwr_init(rw) pthread_rwlock_init(rw, NULL) +# define ldap_pvt_thread_rdwr_destroy(rw) pthread_rwlock_destroy(rw) +# define ldap_pvt_thread_rdwr_rlock(rw) pthread_rwlock_rdlock(rw) +# define ldap_pvt_thread_rdwr_rtrylock(rw) pthread_rwlock_tryrdlock(rw) +# define ldap_pvt_thread_rdwr_runlock(rw) pthread_rwlock_unlock(rw) +# define ldap_pvt_thread_rdwr_wlock(rw) pthread_rwlock_wrlock(rw) +# define ldap_pvt_thread_rdwr_wtrylock(rw) pthread_rwlock_trywrlock(rw) +# define ldap_pvt_thread_rdwr_wunlock(rw) pthread_rwlock_unlock(rw) +#endif /* LDAP_THREAD_HAVE_RDWR && HAVE_PTHREAD_RWLOCK_DESTROY */ +#endif /* HAVE_PTHREADS >= 7 && !LDAP_THREAD_DEBUG */ + LDAP_END_DECL #elif defined ( HAVE_MACH_CTHREADS ) EOP