1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2026-10-14 13:36:34 +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:
Charlie
2026-06-05 10:45:08 +08:00
parent b14262e9eb
commit c44a325384
17 changed files with 178 additions and 82 deletions
+13 -4
View File
@@ -59,10 +59,13 @@ func (s *memStore[T]) Push(ctx context.Context, v T) error {
func (s *memStore[T]) Pop() (T, error) {
for {
_, exist := s.Peek()
if exist {
return s.h.Pop().(T), nil
s.mu.Lock()
if s.h.Len() > 0 {
v := s.h.Pop().(T)
s.mu.Unlock()
return v, nil
}
s.mu.Unlock()
time.Sleep(time.Millisecond * 10)
}
@@ -80,9 +83,15 @@ func (s *memStore[T]) Peek() (T, bool) {
}
func (s *memStore[T]) Len() int {
s.mu.Lock()
defer s.mu.Unlock()
return s.h.Len()
}
func (s *memStore[T]) IsEmpty() bool {
return s.Len() == 0
s.mu.Lock()
defer s.mu.Unlock()
return s.h.Len() == 0
}