-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmessageids.go
More file actions
50 lines (42 loc) · 843 Bytes
/
messageids.go
File metadata and controls
50 lines (42 loc) · 843 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
43
44
45
46
47
48
49
50
package unitdb
import (
"sync"
)
// MID is 32-bit local message identifier
type MID int32
type messageIds struct {
sync.RWMutex
id MID
resumedIds map[MID]struct{}
index map[MID]Result // map[MID]Result
}
func (mids *messageIds) reset(id MID) {
mids.Lock()
defer mids.Unlock()
mids.id = id
}
func (mids *messageIds) freeID(id MID) {
mids.Lock()
defer mids.Unlock()
delete(mids.index, id)
}
func (mids *messageIds) resumeID(id MID) {
mids.Lock()
defer mids.Unlock()
mids.resumedIds[id] = struct{}{}
}
func (mids *messageIds) nextID(r Result) MID {
mids.Lock()
defer mids.Unlock()
mids.id--
if _, ok := mids.resumedIds[mids.id]; ok {
mids.nextID(r)
}
mids.index[mids.id] = r
return mids.id
}
func (mids *messageIds) getType(id MID) Result {
mids.RLock()
defer mids.RUnlock()
return mids.index[id]
}