Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unused pointers in env #146

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions mdbx/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
err = c.getVal2(setkey, setval, 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 @@ -178,8 +177,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 {
JkLondon marked this conversation as resolved.
Show resolved Hide resolved
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 {
JkLondon marked this conversation as resolved.
Show resolved Hide resolved
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
Loading