#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)
#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
}
}
#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