]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/init.c
Unify use of BDB lockers
[openldap] / servers / slapd / back-bdb / init.c
index 7b85509c7b1a1fae7602e6f8e420f04af44cffab..135f101702bc0a0e9d214116b12d8fdb52b56340 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2006 The OpenLDAP Foundation.
+ * Copyright 2000-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -73,6 +73,8 @@ bdb_db_init( BackendDB *be )
 #endif
        ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_head_mutex );
        ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_tail_mutex );
+       ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_count_mutex );
+       ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_eifree_mutex );
        ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex );
        ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
        ldap_pvt_thread_rdwr_init( &bdb->bi_idl_tree_rwlock );
@@ -81,7 +83,7 @@ bdb_db_init( BackendDB *be )
        be->be_private = bdb;
        be->be_cf_ocs = be->bd_info->bi_cf_ocs;
 
-       rc = bdb_monitor_init( be );
+       rc = bdb_monitor_db_init( be );
 
        return rc;
 }
@@ -421,12 +423,8 @@ bdb_db_open( BackendDB *be )
                goto fail;
        }
 
-       if ( !quick ) {
-               XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
-       }
-
        /* monitor setup */
-       rc = bdb_monitor_open( be );
+       rc = bdb_monitor_db_open( be );
        if ( rc != 0 ) {
                goto fail;
        }
@@ -451,7 +449,7 @@ bdb_db_close( BackendDB *be )
        bdb_idl_cache_entry_t *entry, *next_entry;
 
        /* monitor handling */
-       (void)bdb_monitor_close( be );
+       (void)bdb_monitor_db_close( be );
 
        bdb->bi_flags &= ~BDB_IS_OPEN;
 
@@ -471,29 +469,23 @@ bdb_db_close( BackendDB *be )
 
        bdb_cache_release_all (&bdb->bi_cache);
 
-       if ( bdb->bi_idl_cache_max_size ) {
+       if ( bdb->bi_idl_cache_size ) {
                avl_free( bdb->bi_idl_tree, NULL );
                bdb->bi_idl_tree = NULL;
                entry = bdb->bi_idl_lru_head;
-               while ( entry != NULL ) {
+               do {
                        next_entry = entry->idl_lru_next;
                        if ( entry->idl )
                                free( entry->idl );
                        free( entry->kstr.bv_val );
                        free( entry );
                        entry = next_entry;
-               }
+               } while ( entry != bdb->bi_idl_lru_head );
                bdb->bi_idl_lru_head = bdb->bi_idl_lru_tail = NULL;
        }
 
        /* close db environment */
        if( bdb->bi_dbenv ) {
-               /* Free cache locker if we enabled locking */
-               if ( !( slapMode & SLAP_TOOL_QUICK )) {
-                       XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
-                       bdb->bi_cache.c_locker = 0;
-               }
-
                /* force a checkpoint, but not if we were ReadOnly,
                 * and not in Quick mode since there are no transactions there.
                 */
@@ -531,6 +523,9 @@ bdb_db_destroy( BackendDB *be )
 {
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
 
+       /* monitor handling */
+       (void)bdb_monitor_db_destroy( be );
+
        if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
        if( bdb->bi_db_config_path ) ch_free( bdb->bi_db_config_path );
 
@@ -539,6 +534,8 @@ bdb_db_destroy( BackendDB *be )
        ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
        ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_head_mutex );
        ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_tail_mutex );
+       ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_count_mutex );
+       ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_eifree_mutex );
        ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
 #ifdef BDB_HIER
        ldap_pvt_thread_mutex_destroy( &bdb->bi_modrdns_mutex );
@@ -675,14 +672,6 @@ bdb_back_initialize(
        bi->bi_connection_init = 0;
        bi->bi_connection_destroy = 0;
 
-       /*
-        * initialize monitor stuff
-        */
-       rc = bdb_monitor_initialize();
-       if ( rc ) {
-               return rc;
-       }
-
        rc = bdb_back_init_cf( bi );
 
        return rc;