mirror of
https://gitee.com/johng/gf
synced 2026-07-05 13:22:16 +08:00
并发安全容器新增LockFunc/RLockFunc方法,完善Iterator遍历方法注释
This commit is contained in:
@ -22,7 +22,7 @@ func NewStringBoolMap() *StringBoolMap {
|
||||
}
|
||||
}
|
||||
|
||||
// 给定回调函数对原始内容进行遍历
|
||||
// 给定回调函数对原始内容进行遍历,回调函数返回true表示继续遍历,否则停止遍历
|
||||
func (this *StringBoolMap) Iterator(f func (k string, v bool) bool) {
|
||||
this.mu.RLock()
|
||||
for k, v := range this.m {
|
||||
@ -159,3 +159,17 @@ func (this *StringBoolMap) Clear() {
|
||||
this.m = make(map[string]bool)
|
||||
this.mu.Unlock()
|
||||
}
|
||||
|
||||
// 使用自定义方法执行加锁修改操作
|
||||
func (this *StringBoolMap) LockFunc(f func(m map[string]bool)) {
|
||||
this.mu.Lock()
|
||||
f(this.m)
|
||||
this.mu.Unlock()
|
||||
}
|
||||
|
||||
// 使用自定义方法执行加锁读取操作
|
||||
func (this *StringBoolMap) RLockFunc(f func(m map[string]bool)) {
|
||||
this.mu.RLock()
|
||||
f(this.m)
|
||||
this.mu.RUnlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user