From 30b3d741d5dd919e780da7026190fae1078ca931 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 13 Apr 2003 05:48:48 +0000 Subject: [PATCH] Fix prev commit - hash bytes of ldap_pvt_thread_t to find proper slot --- 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 c6eeed959c..4cecaee9da 100644 --- a/libraries/libldap_r/tpool.c +++ b/libraries/libldap_r/tpool.c @@ -170,6 +170,10 @@ ldap_pvt_thread_pool_init ( return(0); } +#define TID_HASH(tid, hash) do { int i; \ + unsigned char *ptr = (unsigned char *)&(tid); \ + for (i=0, hash=0; iltp_starting--; /* assign this thread ID to a key slot; start * at the thread ID itself (mod MAXTHREADS) and * look for an empty slot. */ - for (rc = thr & (MAXTHREADS-1); thread_keys[rc].id; + TID_HASH(thr, hash); + for (rc = hash & (MAXTHREADS-1); thread_keys[rc].id; rc = (rc+1) & (MAXTHREADS-1)); thread_keys[rc].id = thr; } else { @@ -387,7 +393,7 @@ ldap_int_thread_pool_wrapper ( ldap_int_thread_ctx_t *ctx; ldap_int_thread_key_t ltc_key[MAXKEYS]; ldap_pvt_thread_t tid; - int i, keyslot; + int i, keyslot, hash; if (pool == NULL) return NULL; @@ -401,7 +407,8 @@ ldap_int_thread_pool_wrapper ( ldap_pvt_thread_mutex_lock(&pool->ltp_mutex); /* store pointer to our keys */ - for (i = tid & (MAXTHREADS-1); thread_keys[i].id != tid; + TID_HASH(tid, hash); + for (i = hash & (MAXTHREADS-1); thread_keys[i].id != tid; i = (i+1) & (MAXTHREADS-1)); thread_keys[i].ctx = ltc_key; keyslot = i; @@ -533,11 +540,12 @@ int ldap_pvt_thread_pool_setkey( void *ldap_pvt_thread_pool_context( ) { ldap_pvt_thread_t tid; - int i; + int i, hash; tid = ldap_pvt_thread_self(); - for (i = tid & (MAXTHREADS-1); thread_keys[i].id && + TID_HASH( tid, hash ); + for (i = hash & (MAXTHREADS-1); thread_keys[i].id && thread_keys[i].id != tid; i = (i+1) & (MAXTHREADS-1)); return thread_keys[i].ctx; -- 2.39.5