// assumes that env != null and txp != null!
 internal void Initialize(DB_TXN* txp) {
   this.txp = txp;
   txp->api_internal = (IntPtr)instanceHandle;
 }
 Int64 Get(DB_TXN* txp, Int32 delta, ReadFlags flags) {
   Int64 value;
   DbRetVal ret;
   lock (rscLock) {
     DB_SEQUENCE* seqp = CheckDisposed();
     if (SeqGet == null)
       throw new BdbException("Sequence must be open.");
     ret = SeqGet(seqp, txp, delta, out value, unchecked((UInt32)flags));
   }
   Util.CheckRetVal(ret);
   return value;
 }
 DbRetVal Remove(DB_TXN* txp, RemoveFlags flags) {
   DbRetVal ret;
   // always lock Db first, to avoid deadlock
   lock (db.rscLock) {
     lock (rscLock) {
       RuntimeHelpers.PrepareConstrainedRegions();
       try { }
       finally {
         DB_SEQUENCE* seqp = CheckDisposed();
         // DB_SEQUENCE->Remove() could be a lengthy call, so we call Disposed() first, and the
         // CER ensures that we reach DB_SEQUENCE->Remove() without external interruption.
         // This is OK because one must not use the handle after DB_SEQUENCE->Remove() was called,
         // regardless of the return value.
         Disposed();
         ret = seqp->Remove(seqp, txp, unchecked((UInt32)flags));
       }
     }
   }
   return ret;
 }
 DbRetVal Open(DB_TXN* txp, ref DbEntry key, OpenFlags flags) {
   DbRetVal ret;
   lock (rscLock) {
     DB_SEQUENCE* seqp = CheckDisposed();
     fixed (byte* keyBufP = key.Buffer) {
       key.dbt.data = keyBufP + key.Start;
       ret = seqp->Open(seqp, txp, ref key.dbt, unchecked((UInt32)flags));
     }
     // initialize function pointer delegates
     SeqGet = seqp->Get;
   }
   return ret;
 }
 void* GetPage(ref uint pageNo, DB_TXN* txp, CachePageGetFlags flags) {
   DbRetVal ret;
   void* page;
   lock (rscLock) {
     DB_MPOOLFILE* mpf = CheckDisposed();
     ret = mpf->Get(mpf, ref pageNo, txp, flags, out page);
   }
   Util.CheckRetVal(ret);
   return page;
 }
 void LogPrintFile(DB_TXN* txp, byte[] msg) {
   DbRetVal ret;
   lock (rscLock) {
     DB_ENV* evp = CheckDisposed();
     fixed (byte* msgPtr = msg) {
       ret = evp->LogPrintFile(evp, txp, msgPtr);
     }
   }
   Util.CheckRetVal(ret);
 }
 // must be called under an environment and parent lock
 DbRetVal TxnBegin(DB_TXN* parxp, Txn txn, Txn.BeginFlags flags) {
   DbRetVal ret;
   RuntimeHelpers.PrepareConstrainedRegions();
   try { }
   finally {
     DB_TXN* txp;
     DB_ENV* evp = CheckDisposed();
     ret = evp->TxnBegin(evp, parxp, out txp, unchecked((UInt32)flags));
     if (ret == DbRetVal.SUCCESS) {
       txn.Initialize(txp);
       transactions.Insert(txn);
     }
   }
   return ret;
 }
 DbRetVal DbRename(DB_TXN* txp, byte[] fBytes, byte[] dBytes, byte[] nBytes, WriteFlags flags) {
   DB_ENV* evp = CheckDisposed();
   fixed (byte* fp = fBytes, dp = dBytes, np = nBytes) {
     return evp->DbRename(evp, txp, fp, dp, np, unchecked((UInt32)flags));
   }
 }