From: Howard Chu Date: Tue, 23 Aug 2005 04:12:57 +0000 (+0000) Subject: ITS#3961 better fix - provide a context for the main thread. The context X-Git-Tag: OPENLDAP_REL_ENG_2_2_MP~606 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1f78e2b831b1e6610aeef5071578d7549ce7a02f;p=openldap ITS#3961 better fix - provide a context for the main thread. The context must be reset by the caller to clear out temp allocations etc. --- diff --git a/include/ldap_pvt_thread.h b/include/ldap_pvt_thread.h index 75b9998e80..79c821dd65 100644 --- a/include/ldap_pvt_thread.h +++ b/include/ldap_pvt_thread.h @@ -208,11 +208,8 @@ ldap_pvt_thread_pool_purgekey LDAP_P(( void *key )); LDAP_F( void *) ldap_pvt_thread_pool_context LDAP_P(( void )); -LDAP_F( void *) -ldap_pvt_thread_pool_fake_context_init LDAP_P(( void )); - LDAP_F( void ) -ldap_pvt_thread_pool_fake_context_destroy LDAP_P(( void *key )); +ldap_pvt_thread_pool_context_reset LDAP_P(( void *key )); LDAP_END_DECL diff --git a/libraries/libldap_r/tpool.c b/libraries/libldap_r/tpool.c index 675fa4d0b4..440b5a75e5 100644 --- a/libraries/libldap_r/tpool.c +++ b/libraries/libldap_r/tpool.c @@ -96,9 +96,15 @@ static ldap_pvt_thread_mutex_t ldap_pvt_thread_pool_mutex; static void *ldap_int_thread_pool_wrapper( void *pool ); +static ldap_pvt_thread_t ldap_int_main_tid; + +static ldap_int_thread_key_t ldap_int_main_thrctx[LDAP_MAXTHR]; + int ldap_int_thread_pool_startup ( void ) { + ldap_int_main_tid = ldap_pvt_thread_self(); + return ldap_pvt_thread_mutex_init(&ldap_pvt_thread_pool_mutex); } @@ -652,6 +658,8 @@ void *ldap_pvt_thread_pool_context( ) int i, hash; tid = ldap_pvt_thread_self(); + if ( TID_EQ( tid, ldap_int_main_tid )) + return ldap_int_main_thrctx; TID_HASH( tid, hash ); for (i = hash & (LDAP_MAXTHR-1); !TID_EQ(thread_keys[i].id, tid_zero) && @@ -660,21 +668,15 @@ void *ldap_pvt_thread_pool_context( ) return thread_keys[i].ctx; } -void *ldap_pvt_thread_pool_fake_context_init( ) -{ - return LDAP_CALLOC( LDAP_MAXTHR, sizeof(ldap_int_thread_key_t) ); -} - -void ldap_pvt_thread_pool_fake_context_destroy( void *vctx ) +void ldap_pvt_thread_pool_context_reset( void *vctx ) { ldap_int_thread_key_t *ctx = vctx; int i; - for ( i=0; ctx[i].ltk_key; i++) { + for ( i=0; io_bd = &cfb->cb_db; rc = op->o_bd->be_search( op, &rs ); - ldap_pvt_thread_pool_fake_context_destroy( thrctx ); + ldap_pvt_thread_pool_context_reset( thrctx ); } cfb->cb_use_ldif = 1; @@ -3989,7 +3989,7 @@ config_back_db_open( BackendDB *be ) return 0; if ( cfb->cb_use_ldif ) { - thrctx = ldap_pvt_thread_pool_fake_context_init(); + thrctx = ldap_pvt_thread_pool_context(); op = (Operation *)opbuf; connection_fake_init( &conn, op, thrctx ); @@ -4103,7 +4103,7 @@ config_back_db_open( BackendDB *be ) } } if ( thrctx ) - ldap_pvt_thread_pool_fake_context_destroy( thrctx ); + ldap_pvt_thread_pool_context_reset( thrctx ); return 0; } diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c index 978e7c7fd8..2f5d88b65b 100644 --- a/servers/slapd/overlays/syncprov.c +++ b/servers/slapd/overlays/syncprov.c @@ -2111,12 +2111,6 @@ sp_cf_gen(ConfigArgs *c) return rc; } -/* Cheating - we have no thread pool context for these functions, - * so make one. - */ - -static void *syncprov_thrctx; - /* ITS#3456 we cannot run this search on the main thread, must use a * child thread in order to insure we have a big enough stack. */ @@ -2148,6 +2142,7 @@ syncprov_db_open( Entry *e; Attribute *a; int rc; + void *thrctx = NULL; if ( slapMode & SLAP_TOOL_MODE ) { return 0; @@ -2158,8 +2153,8 @@ syncprov_db_open( return rc; } - syncprov_thrctx = ldap_pvt_thread_pool_fake_context_init(); - connection_fake_init( &conn, op, syncprov_thrctx ); + thrctx = ldap_pvt_thread_pool_context(); + connection_fake_init( &conn, op, thrctx ); op->o_bd = be; op->o_dn = be->be_rootdn; op->o_ndn = be->be_rootndn; @@ -2212,6 +2207,7 @@ syncprov_db_open( out: op->o_bd->bd_info = (BackendInfo *)on; + ldap_pvt_thread_pool_context_reset( thrctx ); return 0; } @@ -2234,15 +2230,16 @@ syncprov_db_close( char opbuf[OPERATION_BUFFER_SIZE]; Operation *op = (Operation *)opbuf; SlapReply rs = {REP_RESULT}; + void *thrctx; - connection_fake_init( &conn, op, syncprov_thrctx ); + thrctx = ldap_pvt_thread_pool_context(); + connection_fake_init( &conn, op, thrctx ); op->o_bd = be; op->o_dn = be->be_rootdn; op->o_ndn = be->be_rootndn; syncprov_checkpoint( op, &rs, on ); + ldap_pvt_thread_pool_context_reset( thrctx ); } - ldap_pvt_thread_pool_fake_context_destroy( syncprov_thrctx ); - syncprov_thrctx = NULL; return 0; }