From: Howard Chu Date: Sat, 24 Aug 2002 08:11:08 +0000 (+0000) Subject: Experimental code that uses one locker ID per thread. Seems to work OK, X-Git-Tag: NO_SLAP_OP_BLOCKS~1182 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d6449b1d57964b189259f7388f03418fb09e3000;p=openldap Experimental code that uses one locker ID per thread. Seems to work OK, is enabled by default. #undef BDB_REUSE_LOCKERS in back-bdb.h to disable. Probably needs to be disabled when built with NO_THREADS. --- diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 6eeae509e5..2d7075b993 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -156,8 +156,8 @@ struct bdb_op_info { #define TXN_COMMIT(txn,f) txn_commit((txn), (f)) #define TXN_ABORT(txn) txn_abort((txn)) #define TXN_ID(txn) txn_id(txn) -#define LOCK_ID(env, locker) lock_id(env, locker) -#define LOCK_ID_FREE(env, locker) lock_id_free(env, locker) +#define XLOCK_ID(env, locker) lock_id(env, locker) +#define XLOCK_ID_FREE(env, locker) lock_id_free(env, locker) #else #define LOCK_DETECT(env,f,t,a) (env)->lock_detect(env, f, t, a) #define LOCK_GET(env,i,f,o,m,l) (env)->lock_get(env, i, f, o, m, l) @@ -168,8 +168,18 @@ struct bdb_op_info { #define TXN_COMMIT(txn,f) (txn)->commit((txn), (f)) #define TXN_ABORT(txn) (txn)->abort((txn)) #define TXN_ID(txn) (txn)->id(txn) -#define LOCK_ID(env, locker) (env)->lock_id(env, locker) -#define LOCK_ID_FREE(env, locker) (env)->lock_id_free(env, locker) +#define XLOCK_ID(env, locker) (env)->lock_id(env, locker) +#define XLOCK_ID_FREE(env, locker) (env)->lock_id_free(env, locker) + +#define BDB_REUSE_LOCKERS + +#ifdef BDB_REUSE_LOCKERS +#define LOCK_ID_FREE(env, 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) +#endif #if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17 #undef DB_OPEN diff --git a/servers/slapd/back-bdb/cache.c b/servers/slapd/back-bdb/cache.c index 8f20bcee6f..dcfa51c68e 100644 --- a/servers/slapd/back-bdb/cache.c +++ b/servers/slapd/back-bdb/cache.c @@ -1100,3 +1100,57 @@ bdb_lru_print( Cache *cache ) } } #endif + +#ifdef BDB_REUSE_LOCKERS +void +bdb_locker_id_free( void *key, void *data ) +{ + DB_ENV *env = key; + int lockid = (int) data; + + XLOCK_ID_FREE( env, lockid ); +} + +int +bdb_locker_id( Operation *op, DB_ENV *env, int *locker ) +{ + int i, rc, lockid; + void *data; + + if ( !env || !op || !locker ) return -1; + + /* Shouldn't happen unless we're single-threaded */ + if ( !op->o_threadctx ) { + *locker = 0; + return 0; + } + + if ( ldap_pvt_thread_pool_getkey( op->o_threadctx, env, &data, NULL ) ) { + for ( i=0, rc=1; rc != 0 && i<4; i++ ) { + rc = XLOCK_ID( env, &lockid ); + if (rc) ldap_pvt_thread_yield(); + } + if ( rc != 0) { + return rc; + } + data = (void *)lockid; + if ( ( rc = ldap_pvt_thread_pool_setkey( op->o_threadctx, env, + data, bdb_locker_id_free ) ) ) { + XLOCK_ID_FREE( env, lockid ); +#ifdef NEW_LOGGING + LDAP_LOG( BACK_BDB, ERR, "bdb_locker_id: err %s(%d)\n", + db_strerror(rc), rc, 0 ); +#else + Debug( LDAP_DEBUG_ANY, "bdb_locker_id: err %s(%d)\n", + db_strerror(rc), rc, 0 ); +#endif + + return rc; + } + } else { + lockid = (int)data; + } + *locker = lockid; + return 0; +} +#endif diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 6cef37e39c..1a50eef2be 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -343,6 +343,12 @@ int bdb_cache_delete_entry( ); void bdb_cache_release_all( Cache *cache ); +#ifdef BDB_REUSE_LOCKERS + +int bdb_locker_id( Operation *op, DB_ENV *env, int *locker ); + +#endif + #ifdef HAVE_EBCDIC char *ebcdic_dberror( int rc );