locked_entry.go 860 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package mount
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  4. "sync"
  5. )
  6. type LockedEntry struct {
  7. *filer_pb.Entry
  8. sync.RWMutex
  9. }
  10. func (le *LockedEntry) GetEntry() *filer_pb.Entry {
  11. le.RLock()
  12. defer le.RUnlock()
  13. return le.Entry
  14. }
  15. // SetEntry sets the entry of the LockedEntry
  16. // entry should never be nil
  17. func (le *LockedEntry) SetEntry(entry *filer_pb.Entry) {
  18. le.Lock()
  19. defer le.Unlock()
  20. le.Entry = entry
  21. }
  22. func (le *LockedEntry) UpdateEntry(fn func(entry *filer_pb.Entry)) *filer_pb.Entry {
  23. le.Lock()
  24. defer le.Unlock()
  25. fn(le.Entry)
  26. return le.Entry
  27. }
  28. func (le *LockedEntry) GetChunks() []*filer_pb.FileChunk {
  29. le.RLock()
  30. defer le.RUnlock()
  31. return le.Entry.Chunks
  32. }
  33. func (le *LockedEntry) AppendChunks(newChunks []*filer_pb.FileChunk) {
  34. le.Lock()
  35. defer le.Unlock()
  36. le.Entry.Chunks = append(le.Entry.Chunks, newChunks...)
  37. }