mirror of
https://gitee.com/johng/gf
synced 2026-07-04 21:03:13 +08:00
并发安全容器的并发安全方法改进
This commit is contained in:
@ -159,16 +159,16 @@ func (this *StringStringMap) Clear() {
|
||||
this.mu.Unlock()
|
||||
}
|
||||
|
||||
// 使用自定义方法执行加锁修改操作
|
||||
// 并发安全写锁操作,使用自定义方法执行加锁修改操作
|
||||
func (this *StringStringMap) LockFunc(f func(m map[string]string)) {
|
||||
this.mu.Lock()
|
||||
defer this.mu.Unlock()
|
||||
this.mu.Lock(true)
|
||||
defer this.mu.Unlock(true)
|
||||
f(this.m)
|
||||
}
|
||||
|
||||
// 使用自定义方法执行加锁读取操作
|
||||
// 并发安全读锁操作,使用自定义方法执行加锁读取操作
|
||||
func (this *StringStringMap) RLockFunc(f func(m map[string]string)) {
|
||||
this.mu.RLock()
|
||||
defer this.mu.RUnlock()
|
||||
this.mu.RLock(true)
|
||||
defer this.mu.RUnlock(true)
|
||||
f(this.m)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user