Skip to content

Commit

Permalink
debug: support pprof3
Browse files Browse the repository at this point in the history
  • Loading branch information
yangkaa committed Oct 28, 2024
1 parent 6431a2d commit cef666f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mq/api/mq/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,23 @@ func (kv *KeyValueStore) Put(key, value string) {
kv.cond.Broadcast()
}

// Get 根据键获取第一个值并删除该键值对中的第一个值
// Get 根据键获取第一个值并删除该键值对中的第一个值
func (kv *KeyValueStore) Get(key string) (string, bool) {
kv.mu.RLock() // 使用读锁开始
defer kv.mu.RUnlock()

kv.mu.RLock() // 使用读锁开始
timeout := time.After(5 * time.Second) // 预先创建一个定时器,避免高频创建
for len(kv.data[key]) == 0 {
kv.mu.RUnlock() // 在等待前释放读锁

select {
case <-timeout:
return "", false // 超时后返回空值
default:
kv.cond.L.Lock() // 锁住条件变量
kv.cond.Wait() // 等待条件变量通知
kv.cond.L.Unlock() // 释放条件变量的锁
kv.mu.Lock() // 切换为写锁
kv.cond.Wait() // 等待条件变量通知
kv.mu.Unlock() // 释放写锁
}

kv.mu.RLock() // 重新获得读锁
}

Expand Down

0 comments on commit cef666f

Please sign in to comment.