mirror of
https://github.com/charlienet/go-mixed.git
synced 2026-07-14 08:17:26 +08:00
fix: 修复多处并发安全问题及锁实现重构
locker: 导出 RWLocker/EmptyLocker 接口, 新增 WithRWLocker, 重构 SourceLocker 竞态、Synchronize 数据竞态 collections/linked_list: 补齐 ForEach/Size/GetAt/RemoveAt/ToList 等方法的锁保护 collections/queue,stack: Peek/Size/IsEmpty 加锁 collections/list/linked_list: Front/Back/GetAt 加锁 maps: rwlock_map.Exist/Count, hash_map.Count 加锁 delay_queue/mem_store: Pop 原子化、Len/IsEmpty 加锁 cleanup_guard: Run() 检查 enable 标志 sets/ketama: 修复接口变更导致的 nil 空指针
This commit is contained in:
@@ -40,21 +40,38 @@ func (l *LinkedList[T]) PushFront(v T) *LinkedList[T] {
|
||||
}
|
||||
|
||||
func (l *LinkedList[T]) FrontNode() *LinkedNode[T] {
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
|
||||
return l.front
|
||||
}
|
||||
|
||||
func (l *LinkedList[T]) Front() T {
|
||||
return l.FrontNode().Value
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
|
||||
if l.size == 0 {
|
||||
panic(ErrorOutOffRange)
|
||||
}
|
||||
|
||||
return l.front.Value
|
||||
}
|
||||
|
||||
func (l *LinkedList[T]) BackNode() *LinkedNode[T] {
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
|
||||
return l.tail
|
||||
}
|
||||
|
||||
func (l *LinkedList[T]) Back() T {
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
|
||||
if l.size == 0 {
|
||||
panic(ErrorOutOffRange)
|
||||
}
|
||||
|
||||
return l.tail.Value
|
||||
}
|
||||
|
||||
@@ -70,7 +87,10 @@ func (l *LinkedList[T]) ForEach(fn func(T) bool) {
|
||||
}
|
||||
|
||||
func (l *LinkedList[T]) GetAt(i int) T {
|
||||
if i <= l.Size() {
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
|
||||
if i < l.size {
|
||||
for n, current := 0, l.front; current != nil; current, n = current.Next, n+1 {
|
||||
if n == i {
|
||||
return current.Value
|
||||
|
||||
Reference in New Issue
Block a user