并发安全容器的并发安全方法改进

This commit is contained in:
john
2018-09-06 14:48:55 +08:00
parent ebc10f7779
commit 9d82bb3f2d
19 changed files with 186 additions and 112 deletions

View File

@ -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)
}