File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ type concurrentHandleMap[T any] struct {
11
11
leftMap map [uint64 ]* T
12
12
rightMap map [* T ]uint64
13
13
currentHandle uint64
14
- lock sync.Mutex
14
+ lock sync.RWMutex
15
15
}
16
16
17
17
func newConcurrentHandleMap [T any ]() * concurrentHandleMap [T ] {
@@ -24,6 +24,7 @@ func newConcurrentHandleMap[T any]() *concurrentHandleMap[T] {
24
24
func (cm * concurrentHandleMap [T ]) insert (obj * T ) uint64 {
25
25
cm .lock .Lock ()
26
26
defer cm .lock .Unlock ()
27
+
27
28
if existingHandle , ok := cm .rightMap [obj ]; ok {
28
29
return existingHandle
29
30
}
@@ -36,6 +37,7 @@ func (cm *concurrentHandleMap[T]) insert(obj *T) uint64 {
36
37
func (cm * concurrentHandleMap [T ]) remove (handle uint64 ) bool {
37
38
cm .lock .Lock ()
38
39
defer cm .lock .Unlock ()
40
+
39
41
if val , ok := cm .leftMap [handle ]; ok {
40
42
delete (cm .leftMap , handle )
41
43
delete (cm .rightMap , val )
@@ -44,6 +46,9 @@ func (cm *concurrentHandleMap[T]) remove(handle uint64) bool {
44
46
}
45
47
46
48
func (cm * concurrentHandleMap [T ]) tryGet (handle uint64 ) (* T , bool ) {
49
+ cm .lock .Lock ()
50
+ defer cm .lock .Unlock ()
51
+
47
52
val , ok := cm .leftMap [handle ]
48
53
return val , ok
49
54
}
You can’t perform that action at this time.
0 commit comments