From 104f8cc409822fcdf5aa98ae14f738d869e00eb5 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 19 Sep 2002 06:34:53 +0000 Subject: [PATCH] Simpler fix for NO_THREADS --- servers/slapd/back-bdb/back-bdb.h | 8 +------- servers/slapd/back-bdb/cache.c | 29 ++++++++++++----------------- servers/slapd/back-bdb/init.c | 7 ------- servers/slapd/back-bdb/proto-bdb.h | 2 +- 4 files changed, 14 insertions(+), 32 deletions(-) diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 70e40712d8..56b4150330 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -111,9 +111,6 @@ struct bdb_info { u_int32_t bi_txn_cp_kbyte; int bi_lock_detect; -#ifdef NO_THREADS - int bi_locker_id; -#endif ID bi_lastid; ldap_pvt_thread_mutex_t bi_lastid_mutex; @@ -170,11 +167,8 @@ struct bdb_op_info { #define BDB_REUSE_LOCKERS #ifdef BDB_REUSE_LOCKERS -/* Hack - we depend on "op" and "bdb" being the right variable names - * in each invoker. - */ #define LOCK_ID_FREE(env, locker) -#define LOCK_ID(env, locker) bdb_locker_id(op, bdb, locker) +#define LOCK_ID(env, locker) bdb_locker_id(op, env, locker) #else #define LOCK_ID_FREE(env, locker) XLOCK_ID_FREE(env, locker) #define LOCK_ID(env, locker) XLOCK_ID(env, locker) diff --git a/servers/slapd/back-bdb/cache.c b/servers/slapd/back-bdb/cache.c index 8baf1e710b..a2e43e0db9 100644 --- a/servers/slapd/back-bdb/cache.c +++ b/servers/slapd/back-bdb/cache.c @@ -136,6 +136,9 @@ int bdb_cache_entry_db_lock ( DB_ENV *env, u_int32_t locker, Entry *e, int rw, u_int32_t flags, DB_LOCK *lock ) { +#ifdef NO_THREADS + return 0; +#else int rc; DBT lockobj; int db_rw; @@ -161,16 +164,21 @@ bdb_cache_entry_db_lock #endif } return rc; +#endif /* NO_THREADS */ } int bdb_cache_entry_db_unlock ( DB_ENV *env, DB_LOCK *lock ) { +#ifdef NO_THREADS + return 0; +#else int rc; rc = LOCK_PUT ( env, lock ); return rc; +#endif } /* @@ -1123,29 +1131,17 @@ bdb_locker_id_free( void *key, void *data ) } int -bdb_locker_id( Operation *op, struct bdb_info *bdb, int *locker ) +bdb_locker_id( Operation *op, DB_ENV *env, int *locker ) { int i, rc, lockid; void *data; - DB_ENV *env; - - if ( !bdb || !op || !locker ) return -1; - env = bdb->bi_dbenv; - if ( !env ) return -1; + if ( !env || !op || !locker ) return -1; -#ifdef NO_THREADS - if ( !bdb->bi_locker_id ) { - rc = XLOCK_ID( env, &bdb->bi_locker_id ); - if (rc != 0) return rc; - } - *locker = bdb->bi_locker_id; - return 0; -#else - /* Shouldn't happen */ + /* Shouldn't happen unless we're single-threaded */ if ( !op->o_threadctx ) { *locker = 0; - return -1; + return 0; } if ( ldap_pvt_thread_pool_getkey( op->o_threadctx, env, &data, NULL ) ) { @@ -1175,6 +1171,5 @@ bdb_locker_id( Operation *op, struct bdb_info *bdb, int *locker ) } *locker = lockid; return 0; -#endif /* NO_THREADS */ } #endif diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index d8a9e683d2..7bd08c6726 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -178,9 +178,7 @@ bdb_db_open( BackendDB *be ) bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val ); bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall ); -#ifndef NO_THREADS bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect ); -#endif #ifdef BDB_SUBDIRS { @@ -414,11 +412,6 @@ bdb_db_close( BackendDB *be ) bdb_cache_release_all (&bdb->bi_cache); -#if defined(NO_THREADS) && defined(BDB_REUSE_LOCKERS) - if ( bdb->bi_locker_id ) { - bdb_locker_id_free( bdb->bi_dbenv, bdb->bi_locker_id ); - } -#endif return 0; } diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 262c5a8137..6c7dfeb586 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -366,7 +366,7 @@ void bdb_cache_release_all( Cache *cache ); #ifdef BDB_REUSE_LOCKERS -int bdb_locker_id( Operation *op, struct bdb_info *bdb, int *locker ); +int bdb_locker_id( Operation *op, DB_ENV *env, int *locker ); #endif -- 2.39.5