refactor: moved to locked entry
This commit is contained in:
42
weed/mount/locked_entry.go
Normal file
42
weed/mount/locked_entry.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package mount
|
||||
|
||||
import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type LockedEntry struct {
|
||||
*filer_pb.Entry
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
func (le *LockedEntry) GetEntry() *filer_pb.Entry {
|
||||
le.RLock()
|
||||
defer le.RUnlock()
|
||||
return le.Entry
|
||||
}
|
||||
|
||||
func (le *LockedEntry) SetEntry(entry *filer_pb.Entry) {
|
||||
le.Lock()
|
||||
defer le.Unlock()
|
||||
le.Entry = entry
|
||||
}
|
||||
|
||||
func (le *LockedEntry) UpdateEntry(fn func(entry *filer_pb.Entry)) *filer_pb.Entry {
|
||||
le.Lock()
|
||||
defer le.Unlock()
|
||||
fn(le.Entry)
|
||||
return le.Entry
|
||||
}
|
||||
|
||||
func (le *LockedEntry) GetChunks() []*filer_pb.FileChunk {
|
||||
le.RLock()
|
||||
defer le.RUnlock()
|
||||
return le.Entry.Chunks
|
||||
}
|
||||
|
||||
func (le *LockedEntry) AppendChunks(newChunks []*filer_pb.FileChunk) {
|
||||
le.Lock()
|
||||
defer le.Unlock()
|
||||
le.Entry.Chunks = append(le.Entry.Chunks, newChunks...)
|
||||
}
|
||||
Reference in New Issue
Block a user