]> git.sur5r.net Git - openldap/commitdiff
ITS#3961 provide ldap_pvt_thread_pool_fake_context_init/destroy, don't
authorHoward Chu <hyc@openldap.org>
Tue, 23 Aug 2005 03:25:21 +0000 (03:25 +0000)
committerHoward Chu <hyc@openldap.org>
Tue, 23 Aug 2005 03:25:21 +0000 (03:25 +0000)
use arbitrary context pointers.

include/ldap_pvt_thread.h
libraries/libldap_r/tpool.c
servers/slapd/bconfig.c
servers/slapd/overlays/syncprov.c

index 1ca300bd9861fd79a1d9d0d80c35ca2148cd7dcd..75b9998e80a0bda4855963bed4fefff8372d2274 100644 (file)
@@ -208,6 +208,12 @@ 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_END_DECL
 
 #endif /* _LDAP_THREAD_H */
index 04a71b645c710a9c67a9c0b9c4836f4a6989fdbb..675fa4d0b46e5f1319ad86b7ea6651cc52d99b52 100644 (file)
@@ -660,4 +660,21 @@ 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 )
+{
+       ldap_int_thread_key_t *ctx = vctx;
+       int i;
+
+       for ( i=0; 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 */
index d050122be294e76f174044fb3474f2d60a8f41bb..eb0f575ae0c84d7f5f344e399062dd4146d3fce7 100644 (file)
@@ -2600,8 +2600,10 @@ config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
                return 1;
 
        if ( readit ) {
+               void *thrctx = ldap_pvt_thread_pool_fake_context_init();
+
                op = (Operation *)opbuf;
-               connection_fake_init( &conn, op, cfb );
+               connection_fake_init( &conn, op, thrctx );
 
                filter.f_desc = slap_schema.si_ad_objectClass;
 
@@ -2631,7 +2633,7 @@ config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
                op->o_bd = &cfb->cb_db;
                rc = op->o_bd->be_search( op, &rs );
 
-               slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
+               ldap_pvt_thread_pool_fake_context_destroy( thrctx );
        }
 
        cfb->cb_use_ldif = 1;
@@ -3980,14 +3982,16 @@ config_back_db_open( BackendDB *be )
        Operation *op;
        slap_callback cb = { NULL, slap_null_cb, NULL, NULL };
        SlapReply rs = {REP_RESULT};
+       void *thrctx = NULL;
 
        /* If we read the config from back-ldif, nothing to do here */
        if ( cfb->cb_got_ldif )
                return 0;
 
        if ( cfb->cb_use_ldif ) {
+               thrctx = ldap_pvt_thread_pool_fake_context_init();
                op = (Operation *)opbuf;
-               connection_fake_init( &conn, op, cfb );
+               connection_fake_init( &conn, op, thrctx );
 
                op->o_dn = be->be_rootdn;
                op->o_ndn = be->be_rootndn;
@@ -4098,8 +4102,8 @@ config_back_db_open( BackendDB *be )
                        }
                }
        }
-       if ( op )
-               slap_sl_mem_destroy( NULL, op->o_tmpmemctx );
+       if ( thrctx )
+               ldap_pvt_thread_pool_fake_context_destroy( thrctx );
 
        return 0;
 }
index 4e6ebec2a79d49783112064d4608381c4e3ef850..978e7c7fd8755568c13e7db33652088d659fc8b5 100644 (file)
@@ -2114,15 +2114,8 @@ sp_cf_gen(ConfigArgs *c)
 /* Cheating - we have no thread pool context for these functions,
  * so make one.
  */
-typedef struct thread_keys {
-       void *key;
-       void *data;
-       ldap_pvt_thread_pool_keyfree_t *xfree;
-} thread_keys;
 
-#define MAXKEYS        32
-/* A fake thread context */
-static thread_keys thrctx[MAXKEYS];
+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.
@@ -2165,7 +2158,8 @@ syncprov_db_open(
                return rc;
        }
 
-       connection_fake_init( &conn, op, thrctx );
+       syncprov_thrctx = ldap_pvt_thread_pool_fake_context_init();
+       connection_fake_init( &conn, op, syncprov_thrctx );
        op->o_bd = be;
        op->o_dn = be->be_rootdn;
        op->o_ndn = be->be_rootndn;
@@ -2241,17 +2235,14 @@ syncprov_db_close(
                Operation *op = (Operation *)opbuf;
                SlapReply rs = {REP_RESULT};
 
-               connection_fake_init( &conn, op, thrctx );
+               connection_fake_init( &conn, op, syncprov_thrctx );
                op->o_bd = be;
                op->o_dn = be->be_rootdn;
                op->o_ndn = be->be_rootndn;
                syncprov_checkpoint( op, &rs, on );
        }
-       for ( i=0; thrctx[i].key; i++) {
-               if ( thrctx[i].xfree )
-                       thrctx[i].xfree( thrctx[i].key, thrctx[i].data );
-               thrctx[i].key = NULL;
-       }
+       ldap_pvt_thread_pool_fake_context_destroy( syncprov_thrctx );
+       syncprov_thrctx = NULL;
 
     return 0;
 }