-static void
-bdb_txn_free( void *key, void *data )
-{
- DB_TXN *txn = data;
- TXN_ABORT( txn );
-}
-
-/* Obtain a long-lived transaction for the current thread.
- * If reset == 1, remove the current transaction. */
-static int
-bdb_txn_get( Operation *op, DB_ENV *env, DB_TXN **txn, int reset )
-{
- int i, rc;
- void *ctx, *data = NULL;
-
- if ( slapMode & SLAP_TOOL_MODE ) {
- *txn = NULL;
- return 0;
- }
-
- /* If no op was provided, try to find the ctx anyway... */
- if ( op ) {
- ctx = op->o_threadctx;
- } else {
- ctx = ldap_pvt_thread_pool_context();
- }
-
- /* Shouldn't happen unless we're single-threaded */
- if ( !ctx ) {
- *txn = NULL;
- return 0;
- }
-
- if ( reset ) {
- TXN_ABORT( *txn );
- return ldap_pvt_thread_pool_setkey( ctx, ((char *)env)+1, NULL, NULL );
- }
-
- if ( ldap_pvt_thread_pool_getkey( ctx, ((char *)env)+1, &data, NULL ) ||
- data == NULL ) {
- for ( i=0, rc=1; rc != 0 && i<4; i++ ) {
- rc = TXN_BEGIN( env, NULL, txn, READ_TXN_FLAG );
-#if DB_VERSION_FULL == 0x04020034
- if ( rc == EINVAL && READ_TXN_FLAG ) {
- READ_TXN_FLAG = 0;
- Debug( LDAP_DEBUG_ANY,
- "bdb_txn_get: BerkeleyDB 4.2.52 library needs TXN patch!\n",
- 0, 0, 0 );
- i--;
- continue;
- }
-#endif
- if (rc) ldap_pvt_thread_yield();
- }
- if ( rc != 0) {
- return rc;
- }
- if ( ( rc = ldap_pvt_thread_pool_setkey( ctx, ((char *)env)+1,
- *txn, bdb_txn_free ) ) ) {
- TXN_ABORT( *txn );
- Debug( LDAP_DEBUG_ANY, "bdb_txn_get: err %s(%d)\n",
- db_strerror(rc), rc, 0 );
-
- return rc;
- }
- } else {
- *txn = data;
- }
- return 0;
-}
-