mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
RWMutex does not help here and could hurt
Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright 2021 The NATS Authors
|
||||
// Copyright 2021-2023 The NATS Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@@ -23,7 +23,7 @@ const ipQueueDefaultMaxRecycleSize = 4 * 1024
|
||||
// This is a generic intra-process queue.
|
||||
type ipQueue[T any] struct {
|
||||
inprogress int64
|
||||
sync.RWMutex
|
||||
sync.Mutex
|
||||
ch chan struct{}
|
||||
elts []T
|
||||
pos int
|
||||
@@ -180,9 +180,9 @@ func (q *ipQueue[T]) recycle(elts *[]T) {
|
||||
|
||||
// Returns the current length of the queue.
|
||||
func (q *ipQueue[T]) len() int {
|
||||
q.RLock()
|
||||
q.Lock()
|
||||
l := len(q.elts) - q.pos
|
||||
q.RUnlock()
|
||||
q.Unlock()
|
||||
return l
|
||||
}
|
||||
|
||||
|
||||
@@ -221,9 +221,9 @@ func TestIPQueuePopOne(t *testing.T) {
|
||||
q.push(1)
|
||||
q.push(2)
|
||||
// Capture current capacity
|
||||
q.RLock()
|
||||
q.Lock()
|
||||
c := cap(q.elts)
|
||||
q.RUnlock()
|
||||
q.Unlock()
|
||||
e, ok = q.popOne()
|
||||
if !ok || e != 1 {
|
||||
t.Fatalf("Invalid value: %v", e)
|
||||
@@ -343,9 +343,9 @@ func TestIPQueueRecycle(t *testing.T) {
|
||||
values = q.pop()
|
||||
q.recycle(&values)
|
||||
q.push(1002)
|
||||
q.RLock()
|
||||
q.Lock()
|
||||
recycled := &q.elts == &values
|
||||
q.RUnlock()
|
||||
q.Unlock()
|
||||
if recycled {
|
||||
t.Fatalf("Unexpected recycled slice")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user