Skip to content

Commit

Permalink
wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
octu0 committed May 11, 2023
1 parent f695ba5 commit fbbcd99
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 3 additions & 4 deletions datafile/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package datafile
import (
"hash/crc32"
"io"
goruntime "runtime"
"time"

"github.com/octu0/bitcaskdb/runtime"
Expand Down Expand Up @@ -34,7 +33,7 @@ type Entry struct {
}

func (e *Entry) setFinalizer() {
goruntime.SetFinalizer(e, finalizeEntry)
runtime.SetFinalizer(e, finalizeEntry)
}

func (e *Entry) Read(p []byte) (int, error) {
Expand All @@ -44,7 +43,7 @@ func (e *Entry) Read(p []byte) (int, error) {
func (e *Entry) Close() error {
if e.closed != true {
e.closed = true
goruntime.SetFinalizer(e, nil) // clear finalizer
runtime.SetFinalizer(e, nil) // clear finalizer
if e.release != nil {
e.release()
}
Expand Down Expand Up @@ -76,6 +75,6 @@ func (e *Entry) Validate(ctx runtime.Context) error {
}

func finalizeEntry(e *Entry) {
goruntime.SetFinalizer(e, nil) // clear finalizer
runtime.SetFinalizer(e, nil) // clear finalizer
e.Close()
}
10 changes: 5 additions & 5 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"math"
"os"
"path/filepath"
goruntime "runtime"
"runtime"
"sort"
"sync"
"time"
Expand Down Expand Up @@ -402,7 +402,7 @@ func (t *mergeTempDB) Destroy(lim *priorate.Limiter) {
return
}

goruntime.SetFinalizer(t, nil) // clear
runtime.SetFinalizer(t, nil) // clear
t.SyncAndClose()

files, err := filepath.Glob(filepath.Join(t.tempDir, "*"))
Expand Down Expand Up @@ -436,7 +436,7 @@ func openMergeTempDB(basedir string, opt *option) (*mergeTempDB, error) {
closed: false,
destroyed: false,
}
goruntime.SetFinalizer(st, finalizeMergeTempDB)
runtime.SetFinalizer(st, finalizeMergeTempDB)
return st, nil
}

Expand Down Expand Up @@ -491,7 +491,7 @@ func (st *snapshotTrie) Destroy(lim *priorate.Limiter) {
return
}

goruntime.SetFinalizer(st, nil)
runtime.SetFinalizer(st, nil)
st.Close()
removeFileSlowly([]string{st.file.Name()}, lim)
st.destroyed = true
Expand All @@ -512,7 +512,7 @@ func openSnapshotTrie(tempDir string) (*snapshotTrie, error) {
closed: false,
destroyed: false,
}
goruntime.SetFinalizer(st, finalizeSnapshotTrie)
runtime.SetFinalizer(st, finalizeSnapshotTrie)
return st, nil
}

Expand Down
9 changes: 9 additions & 0 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package runtime

import (
goruntime "runtime"
)

func SetFinalizer(obj interface{}, finalizer interface{}) {
goruntime.SetFinalizer(obj, finalizer)
}

0 comments on commit fbbcd99

Please sign in to comment.