Apply .gitignore rules

This commit is contained in:
皮蛋13361098506
2025-01-06 16:21:36 +08:00
parent 1b77f62820
commit ccd2c530cf
580 changed files with 69806 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package syncUtil
import (
"sync"
)
// 读写锁工具类
type RWLockerUtil struct {
// 锁集合
lockerMap map[string]*RWLocker
// 锁对象
rwMutex sync.RWMutex
}
// 创建新的锁工具类
func NewRWLockerUtil() *RWLockerUtil {
return &RWLockerUtil{
lockerMap: make(map[string]*RWLocker, 8),
}
}
// 获取锁对象
// lockName:锁名
// 返回值:
// RWLocker:读写锁对象
func (this *RWLockerUtil) GetLock(lockName string) *RWLocker {
var rwLockerObj *RWLocker
var exists bool
func() {
this.rwMutex.RLock()
defer this.rwMutex.RUnlock()
rwLockerObj, exists = this.lockerMap[lockName]
}()
if exists {
return rwLockerObj
}
this.rwMutex.Lock()
defer this.rwMutex.Unlock()
rwLockerObj, exists = this.lockerMap[lockName]
if exists == false {
rwLockerObj = NewRWLocker()
this.lockerMap[lockName] = rwLockerObj
}
return rwLockerObj
}
// 释放读写锁对象
// lockName:锁名
func (this *RWLockerUtil) ReleaseLock(lockName string) {
this.rwMutex.Lock()
defer this.rwMutex.Unlock()
delete(this.lockerMap, lockName)
}