Skip to content

Commit

Permalink
remove unused pointers in env (#146)
Browse files Browse the repository at this point in the history
* save

* save
  • Loading branch information
AskAlexSharov authored Jun 19, 2024
1 parent 250d220 commit 8446bb6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
6 changes: 2 additions & 4 deletions mdbx/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
err = c.getValEmpty(op)
}
if err != nil {
c.txn.key = C.MDBX_val{}
c.txn.val = C.MDBX_val{}
c.txn.key, c.txn.val = C.MDBX_val{}, C.MDBX_val{}
return nil, nil, err
}

Expand All @@ -173,8 +172,7 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error

// Clear transaction storage record storage area for future use and to
// prevent dangling references.
c.txn.key = C.MDBX_val{}
c.txn.val = C.MDBX_val{}
c.txn.key, c.txn.val = C.MDBX_val{}, C.MDBX_val{}

return key, val, nil
}
Expand Down
25 changes: 7 additions & 18 deletions mdbx/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ type DBI C.MDBX_dbi
// See MDBX_env.
type Env struct {
_env *C.MDBX_env
ckey *C.MDBX_val
cval *C.MDBX_val

// closeLock is used to allow the Txn finalizer to check if the Env has
// been closed, so that it may know if it must abort.
Expand All @@ -140,8 +138,6 @@ func NewEnv() (*Env, error) {
if ret != success {
return nil, operrno("mdbx_env_create", ret)
}
env.ckey = (*C.MDBX_val)(C.malloc(C.size_t(unsafe.Sizeof(C.MDBX_val{}))))
env.cval = (*C.MDBX_val)(C.malloc(C.size_t(unsafe.Sizeof(C.MDBX_val{}))))
return env, nil
}

Expand Down Expand Up @@ -234,11 +230,6 @@ func (env *Env) Close() {
C.mdbx_env_close(env._env)
env._env = nil
env.closeLock.Unlock()

C.free(unsafe.Pointer(env.ckey))
C.free(unsafe.Pointer(env.cval))
env.ckey = nil
env.cval = nil
}

// CopyFD copies env to the the file descriptor fd.
Expand Down Expand Up @@ -534,7 +525,7 @@ func (env *Env) BeginTxn(parent *Txn, flags uint) (*Txn, error) {
//
// See mdbx_txn_begin.
func (env *Env) RunTxn(flags uint, fn TxnOp) error {
return env.run(false, flags, fn)
return env.run(flags, fn)
}

// View creates a readonly transaction with a consistent view of the
Expand All @@ -548,7 +539,7 @@ func (env *Env) RunTxn(flags uint, fn TxnOp) error {
// Any call to Commit, Abort, Reset or Renew on a Txn created by View will
// panic.
func (env *Env) View(fn TxnOp) error {
return env.run(false, Readonly, fn)
return env.run(Readonly, fn)
}

// Update calls fn with a writable transaction. Update commits the transaction
Expand All @@ -575,7 +566,9 @@ func (env *Env) View(fn TxnOp) error {
// Any call to Commit, Abort, Reset or Renew on a Txn created by Update will
// panic.
func (env *Env) Update(fn TxnOp) error {
return env.run(true, 0, fn)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
return env.run(0, fn)
}

// UpdateLocked behaves like Update but does not lock the calling goroutine to
Expand All @@ -596,14 +589,10 @@ func (env *Env) Update(fn TxnOp) error {
// Any call to Commit, Abort, Reset or Renew on a Txn created by UpdateLocked
// will panic.
func (env *Env) UpdateLocked(fn TxnOp) error {
return env.run(false, 0, fn)
return env.run(0, fn)
}

func (env *Env) run(lock bool, flags uint, fn TxnOp) error {
if lock {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
}
func (env *Env) run(flags uint, fn TxnOp) error {
txn, err := beginTxn(env, nil, flags)
if err != nil {
return err
Expand Down

0 comments on commit 8446bb6

Please sign in to comment.