-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathregistry.go
More file actions
42 lines (35 loc) · 702 Bytes
/
Copy pathregistry.go
File metadata and controls
42 lines (35 loc) · 702 Bytes
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
package alephzero
import (
"sync"
)
type registryDef struct {
mutex sync.Mutex
objs map[uintptr]interface{}
nextId uintptr
}
func newGlobalCallbackRegistry() *registryDef {
return ®istryDef{
objs: make(map[uintptr]interface{}),
}
}
var registry = ®istryDef{
objs: make(map[uintptr]interface{}),
}
func (r *registryDef) Register(obj interface{}) (id uintptr) {
r.mutex.Lock()
defer r.mutex.Unlock()
id = r.nextId
r.nextId++
r.objs[id] = obj
return
}
func (r *registryDef) Unregister(id uintptr) {
r.mutex.Lock()
defer r.mutex.Unlock()
delete(r.objs, id)
}
func (r *registryDef) Get(id uintptr) interface{} {
r.mutex.Lock()
defer r.mutex.Unlock()
return r.objs[id]
}