aboutsummaryrefslogtreecommitdiff
path: root/weed/mount/locked_entry.go
blob: c5fbaee91a0fc355cef99327edc64945edd4b341 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
}

// SetEntry sets the entry of the LockedEntry
// entry should never be nil
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...)
}