From a54549f1d5ee0d7aecef2c18da517211d91145b2 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 2 May 2003 12:23:31 +0000 Subject: [PATCH] Use pthread_equal to compare thread IDs --- libraries/libldap_r/tpool.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libraries/libldap_r/tpool.c b/libraries/libldap_r/tpool.c index 4cecaee9da..5fc4d709d6 100644 --- a/libraries/libldap_r/tpool.c +++ b/libraries/libldap_r/tpool.c @@ -43,6 +43,13 @@ typedef struct ldap_int_thread_key_s { #define MAXKEYS 32 #define MAXTHREADS 1024 /* must be a power of 2 */ +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; @@ -249,7 +256,8 @@ ldap_pvt_thread_pool_submit ( * look for an empty slot. */ TID_HASH(thr, hash); - for (rc = hash & (MAXTHREADS-1); thread_keys[rc].id; + for (rc = hash & (MAXTHREADS-1); + !TID_EQ(thread_keys[rc].id, tid_zero); rc = (rc+1) & (MAXTHREADS-1)); thread_keys[rc].id = thr; } else { @@ -408,7 +416,7 @@ ldap_int_thread_pool_wrapper ( /* store pointer to our keys */ TID_HASH(tid, hash); - for (i = hash & (MAXTHREADS-1); thread_keys[i].id != tid; + for (i = hash & (MAXTHREADS-1); !TID_EQ(thread_keys[i].id, tid); i = (i+1) & (MAXTHREADS-1)); thread_keys[i].ctx = ltc_key; keyslot = i; @@ -478,7 +486,7 @@ ldap_int_thread_pool_wrapper ( } thread_keys[keyslot].ctx = NULL; - thread_keys[keyslot].id = 0; + thread_keys[keyslot].id = tid_zero; pool->ltp_open_count--; ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex); @@ -545,8 +553,8 @@ void *ldap_pvt_thread_pool_context( ) tid = ldap_pvt_thread_self(); TID_HASH( tid, hash ); - for (i = hash & (MAXTHREADS-1); thread_keys[i].id && - thread_keys[i].id != tid; i = (i+1) & (MAXTHREADS-1)); + for (i = hash & (MAXTHREADS-1); !TID_EQ(thread_keys[i].id, tid_zero) && + !TID_EQ(thread_keys[i].id, tid); i = (i+1) & (MAXTHREADS-1)); return thread_keys[i].ctx; } -- 2.39.5