must be reset by the caller to clear out temp allocations etc.
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
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);
}
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) &&
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; i<MAXKEYS && ctx[i].ltk_key; i++) {
if ( ctx[i].ltk_free )
ctx[i].ltk_free( ctx[i].ltk_key, ctx[i].ltk_data );
ctx[i].ltk_key = NULL;
}
- LDAP_FREE( vctx );
}
#endif /* LDAP_THREAD_HAVE_TPOOL */
return 1;
if ( readit ) {
- void *thrctx = ldap_pvt_thread_pool_fake_context_init();
+ void *thrctx = ldap_pvt_thread_pool_context();
op = (Operation *)opbuf;
connection_fake_init( &conn, op, thrctx );
op->o_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;
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 );
}
}
if ( thrctx )
- ldap_pvt_thread_pool_fake_context_destroy( thrctx );
+ ldap_pvt_thread_pool_context_reset( thrctx );
return 0;
}
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.
*/
Entry *e;
Attribute *a;
int rc;
+ void *thrctx = NULL;
if ( slapMode & SLAP_TOOL_MODE ) {
return 0;
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;
out:
op->o_bd->bd_info = (BackendInfo *)on;
+ ldap_pvt_thread_pool_context_reset( thrctx );
return 0;
}
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;
}