Skip to content

Commit

Permalink
finalizer apply from outside
Browse files Browse the repository at this point in the history
  • Loading branch information
octu0 committed May 12, 2023
1 parent 9e70e8d commit 311dbf1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 11 deletions.
4 changes: 0 additions & 4 deletions codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ type Payload struct {
release func()
}

func (p *Payload) setFinalizer() {
runtime.SetFinalizer(p, finalizePayload)
}

func (p *Payload) Read(buf []byte) (int, error) {
return p.Value.Read(buf)
}
Expand Down
2 changes: 1 addition & 1 deletion codec/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (d *Decoder) Decode() (*Payload, error) {
ValueSize: header.ValueSize,
release: releaseFn,
}
p.setFinalizer()
runtime.SetFinalizer(p, finalizePayload)
d.r.Seek(p.N, io.SeekCurrent)
d.offset += p.N
return p, nil
Expand Down
5 changes: 3 additions & 2 deletions datafile/datafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"

"github.com/octu0/bitcaskdb/codec"
"github.com/octu0/bitcaskdb/runtime"
)

type EOFType bool
Expand Down Expand Up @@ -111,7 +112,7 @@ func (df *defaultDatafile) Read() (*Entry, error) {
p.Close()
},
}
e.setFinalizer()
runtime.SetFinalizer(e, finalizeEntry)
return e, nil
}

Expand Down Expand Up @@ -189,7 +190,7 @@ func (df *defaultDatafile) ReadAt(index, size int64) (*Entry, error) {
f.Close()
},
}
e.setFinalizer()
runtime.SetFinalizer(e, finalizeEntry)
return e, nil
}

Expand Down
4 changes: 0 additions & 4 deletions datafile/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ type Entry struct {
release func()
}

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

func (e *Entry) Read(p []byte) (int, error) {
return e.Value.Read(p)
}
Expand Down

0 comments on commit 311dbf1

Please sign in to comment.