MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / Lock

Method Lock

internal/utils/fs/locker.go:33–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31}
32
33func (this *Locker) Lock() error {
34 if this.fp == nil {
35 fp, err := os.OpenFile(this.path, os.O_CREATE|os.O_WRONLY, 0666)
36 if err != nil {
37 return err
38 }
39 this.fp = fp
40 }
41
42 for {
43 b, err := this.tryLock()
44 if err != nil {
45 _ = this.fp.Close()
46 return err
47 }
48 if b {
49 return nil
50 }
51 time.Sleep(100 * time.Millisecond)
52 }
53}
54
55func (this *Locker) Release() error {
56 err := this.fp.Close()

Callers 15

openFunction · 0.95
SharedHttpClientFunction · 0.45
PutMethod · 0.45
initMethod · 0.45
AddMethod · 0.45
RemoveMethod · 0.45
AddMethod · 0.45
RemoveMethod · 0.45
CleanMethod · 0.45
gcItemsMethod · 0.45
NewNoStatFunction · 0.45
CloseMethod · 0.45

Calls 2

tryLockMethod · 0.95
CloseMethod · 0.65

Tested by 6

TestLocker_LockFunction · 0.36
TestManyListsFunction · 0.36
TestMemoryStorage_LockerFunction · 0.36
BenchmarkValuesMapFunction · 0.36