锁步(帧)同步实现

This commit is contained in:
kercylan98
2023-04-20 16:40:47 +08:00
parent 644c520454
commit e6d2eabb65
6 changed files with 132 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ func NewMap[Key comparable, value any]() *Map[Key, value] {
}
}
// Map 并发安全的字典数据结构
type Map[Key comparable, Value any] struct {
lock sync.RWMutex
data map[Key]Value
@@ -78,6 +79,14 @@ func (slf *Map[Key, Value]) DeleteExist(key Key) bool {
return true
}
func (slf *Map[Key, Value]) Clear() {
slf.lock.Lock()
defer slf.lock.Unlock()
for k := range slf.data {
delete(slf.data, k)
}
}
func (slf *Map[Key, Value]) Range(handle func(key Key, value Value)) {
slf.lock.RLock()
defer slf.lock.RUnlock()