u_int32_t bi_txn_cp_min;
u_int32_t bi_txn_cp_kbyte;
-#ifndef NO_THREADS
int bi_lock_detect;
- int bi_lock_detect_seconds;
- ldap_pvt_thread_t bi_lock_detect_tid;
+#ifdef NO_THREADS
+ int bi_locker_id;
#endif
ID bi_lastid;
#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, env, locker)
+#define LOCK_ID(env, locker) bdb_locker_id(op, bdb, locker)
#else
#define LOCK_ID_FREE(env, locker) XLOCK_ID_FREE(env, locker)
#define LOCK_ID(env, locker) XLOCK_ID(env, locker)
}
int
-bdb_locker_id( Operation *op, DB_ENV *env, int *locker )
+bdb_locker_id( Operation *op, struct bdb_info *bdb, int *locker )
{
int i, rc, lockid;
void *data;
+ DB_ENV *env;
- if ( !env || !op || !locker ) return -1;
+ if ( !bdb || !op || !locker ) return -1;
- /* Shouldn't happen unless we're single-threaded */
+ env = bdb->bi_dbenv;
+ if ( !env ) 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 */
if ( !op->o_threadctx ) {
*locker = 0;
- return 0;
+ return -1;
}
if ( ldap_pvt_thread_pool_getkey( op->o_threadctx, env, &data, NULL ) ) {
}
*locker = lockid;
return 0;
+#endif /* NO_THREADS */
}
#endif
/* lock detect configuration */
} else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
-#ifndef NO_THREADS
- if ( argc < 3 ) {
+ if ( argc < 2 ) {
fprintf( stderr, "%s: line %d: "
- "missing parameters in \"lockDetect <policy> <seconds>\" line\n",
+ "missing parameters in \"lockDetect <policy>\" line\n",
fname, lineno );
return 1;
}
} else {
fprintf( stderr, "%s: line %d: "
- "bad policy (%s) in \"lockDetect <policy> <seconds>\" line\n",
+ "bad policy (%s) in \"lockDetect <policy>\" line\n",
fname, lineno, argv[1] );
return 1;
}
- bdb->bi_lock_detect_seconds = strtol( argv[2], NULL, 0 );
- if( bdb->bi_lock_detect_seconds < 1 ) {
- fprintf( stderr, "%s: line %d: "
- "bad seconds (%s) in \"lockDetect <policy> <seconds>\" line\n",
- fname, lineno, argv[2] );
- return 1;
- }
-#else
- fprintf( stderr, "%s: line %d: "
- "NO THREADS: lockDetect line ignored\n",
- fname, lineno );
-#endif
-
/* mode with which to create new database files */
} else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
if ( argc < 2 ) {
bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
-#ifndef NO_THREADS
-#if 0
- bdb->bi_lock_detect = DB_LOCK_NORUN;
-#else
bdb->bi_lock_detect = DB_LOCK_DEFAULT;
-#endif
-#endif
ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
return 0;
}
-#if 0 /* ifndef NO_THREADS */
-static void *lock_detect_task( void *arg )
-{
- struct bdb_info *bdb = (struct bdb_info *) arg;
-
- while( bdb->bi_dbenv != NULL ) {
- int rc;
- int aborted;
- sleep( bdb->bi_lock_detect_seconds );
-
- rc = LOCK_DETECT( bdb->bi_dbenv, 0,
- bdb->bi_lock_detect, &aborted );
-
- if( rc != 0 ) {
- break;
- }
-
-#ifdef NEW_LOGGING
- LDAP_LOG( BACK_BDB, ERR, "bdb_db_init: aborted %d locks\n",
- aborted, 0, 0 );
-#else
- Debug( LDAP_DEBUG_ANY,
- "bdb_lock_detect: aborted %d locks\n",
- aborted, 0, 0 );
-#endif
- }
-
- return NULL;
-}
-#endif
-
int
bdb_bt_compare(
DB *db,
be->be_suffix[0].bv_val, 0, 0 );
#endif
- db_env_set_func_free( ber_memfree );
- db_env_set_func_malloc( ber_memalloc );
- db_env_set_func_realloc( ber_memrealloc );
-
/* we should check existance of dbenv_home and db_directory */
rc = db_env_create( &bdb->bi_dbenv, 0 );
#ifdef BDB_HIER
rc = bdb_build_tree( be );
#endif
-
-#if 0 /* ifndef NO_THREADS */
- if( bdb->bi_lock_detect != DB_LOCK_NORUN ) {
- /* listener as a separate THREAD */
- rc = ldap_pvt_thread_create( &bdb->bi_lock_detect_tid,
- 1, lock_detect_task, bdb );
- }
-#endif
return 0;
}
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;
}
#endif
}
-#if 0
- db_env_set_func_malloc( ch_malloc );
- db_env_set_func_realloc( ch_realloc );
- db_env_set_func_free( ch_free );
-#endif
-
+ db_env_set_func_free( ber_memfree );
+ db_env_set_func_malloc( (db_malloc *)ber_memalloc );
+ db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
db_env_set_func_yield( ldap_pvt_thread_yield );
{
#ifdef BDB_REUSE_LOCKERS
-int bdb_locker_id( Operation *op, DB_ENV *env, int *locker );
+int bdb_locker_id( Operation *op, struct bdb_info *bdb, int *locker );
#endif