-
Notifications
You must be signed in to change notification settings - Fork 21
/
workmap.go
60 lines (51 loc) · 1.19 KB
/
workmap.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package worker
import (
"github.com/MG-RAST/AWE/lib/core"
)
type WorkMap struct {
core.RWMutex
_map map[core.Workunit_Unique_Identifier]int
}
func NewWorkMap() *WorkMap {
wm := &WorkMap{_map: make(map[core.Workunit_Unique_Identifier]int)}
wm.RWMutex.Init("WorkMap")
return wm
}
func (this *WorkMap) Get(id core.Workunit_Unique_Identifier) (value int, ok bool, err error) {
rlock, err := this.RLockNamed("Get")
if err != nil {
return
}
defer this.RUnlockNamed(rlock)
value, ok = this._map[id]
return
}
func (this *WorkMap) GetKeys() (value []core.Workunit_Unique_Identifier, err error) {
rlock, err := this.RLockNamed("Get")
if err != nil {
return
}
defer this.RUnlockNamed(rlock)
for work, _ := range this._map {
value = append(value, work)
}
return
}
func (this *WorkMap) Set(id core.Workunit_Unique_Identifier, value int, name string) (err error) {
err = this.LockNamed("Set_" + name)
if err != nil {
return
}
defer this.Unlock()
this._map[id] = value
return
}
func (this *WorkMap) Delete(id core.Workunit_Unique_Identifier) (err error) {
rlock, err := this.RLockNamed("Get")
if err != nil {
return
}
defer this.RUnlockNamed(rlock)
delete(this._map, id)
return
}