From: Howard Chu Date: Thu, 25 Oct 2007 06:48:44 +0000 (+0000) Subject: Use thread-specific data in pool_context() X-Git-Tag: OPENLDAP_REL_ENG_2_4_9~20^2~473 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=183ff5120cc0ae09fa7664cd4c77464bafbc1697;p=openldap Use thread-specific data in pool_context() --- diff --git a/libraries/libldap_r/tpool.c b/libraries/libldap_r/tpool.c index 8309089cc7..5d883c8fa7 100644 --- a/libraries/libldap_r/tpool.c +++ b/libraries/libldap_r/tpool.c @@ -126,6 +126,8 @@ static ldap_pvt_thread_mutex_t ldap_pvt_thread_pool_mutex; static void *ldap_int_thread_pool_wrapper( void *pool ); +static ldap_pvt_thread_key_t ldap_tpool_key; + /* Context of the main thread */ static ldap_int_thread_userctx_t ldap_int_main_thrctx; @@ -133,6 +135,7 @@ int ldap_int_thread_pool_startup ( void ) { ldap_int_main_thrctx.ltu_id = ldap_pvt_thread_self(); + ldap_pvt_thread_key_create( &ldap_tpool_key ); return ldap_pvt_thread_mutex_init(&ldap_pvt_thread_pool_mutex); } @@ -145,6 +148,7 @@ ldap_int_thread_pool_shutdown ( void ) (ldap_pvt_thread_pool_destroy)(&pool, 0); /* ignore thr_debug macro */ } ldap_pvt_thread_mutex_destroy(&ldap_pvt_thread_pool_mutex); + ldap_pvt_thread_key_destroy( ldap_tpool_key ); return(0); } @@ -552,6 +556,8 @@ ldap_int_thread_pool_wrapper ( ctx.ltu_id = ldap_pvt_thread_self(); TID_HASH(ctx.ltu_id, hash); + ldap_pvt_thread_setdata( ldap_tpool_key, &ctx ); + ldap_pvt_thread_mutex_lock(&pool->ltp_mutex); /* thread_keys[] is read-only when paused */ @@ -819,29 +825,10 @@ void ldap_pvt_thread_pool_purgekey( void *key ) */ void *ldap_pvt_thread_pool_context( ) { - ldap_pvt_thread_t tid; - unsigned i, hash; - ldap_int_thread_userctx_t *ctx; - - tid = ldap_pvt_thread_self(); - if ( ldap_pvt_thread_equal( tid, ldap_int_main_thrctx.ltu_id )) - return &ldap_int_main_thrctx; - - TID_HASH( tid, hash ); - i = hash &= (LDAP_MAXTHR-1); - ldap_pvt_thread_mutex_lock(&ldap_pvt_thread_pool_mutex); - do { - ctx = thread_keys[i].ctx; - if ( ctx == DELETED_THREAD_CTX ) - continue; - if ( !ctx || ldap_pvt_thread_equal(thread_keys[i].ctx->ltu_id, tid) ) - goto done; - } while ( (i = (i+1) & (LDAP_MAXTHR-1)) != hash ); - ctx = NULL; - done: - ldap_pvt_thread_mutex_unlock(&ldap_pvt_thread_pool_mutex); + void *ctx = NULL; - return ctx; + ldap_pvt_thread_key_getdata( ldap_tpool_key, &ctx ); + return ctx ? ctx : &ldap_int_main_thrctx; } /*