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;
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);
}
(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);
}
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 */
*/
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;
}
/*