Rename package circ to queue.

This commit is contained in:
2023-03-03 20:09:51 -08:00
parent b00fe25128
commit f7474fb673
4 changed files with 109 additions and 104 deletions

View File

@@ -31,7 +31,7 @@ import (
"sync"
"gogs.humancabbage.net/sam/priorityq"
"gogs.humancabbage.net/sam/priorityq/circ"
"gogs.humancabbage.net/sam/priorityq/queue"
)
// Q is a concurrent, dual-priority message queue.
@@ -41,8 +41,8 @@ type Q[T any] struct {
// Make a new queue.
func Make[T any](cap int) Q[T] {
high := circ.Make[T](cap)
low := circ.Make[T](cap)
high := queue.Make[T](cap)
low := queue.Make[T](cap)
s := &state[T]{
high: high,
low: low,
@@ -55,8 +55,8 @@ func Make[T any](cap int) Q[T] {
type state[T any] struct {
mu sync.Mutex
high circ.B[T]
low circ.B[T]
high queue.Q[T]
low queue.Q[T]
canSendHigh sync.Cond
canSendLow sync.Cond
canRecv sync.Cond
@@ -163,7 +163,7 @@ func (s *state[T]) TrySendLow(value T) error {
return s.trySend(value, &s.low)
}
func (s *state[T]) send(value T, buf *circ.B[T], cond *sync.Cond) {
func (s *state[T]) send(value T, buf *queue.Q[T], cond *sync.Cond) {
s.mu.Lock()
defer s.mu.Unlock()
for {
@@ -181,7 +181,7 @@ func (s *state[T]) send(value T, buf *circ.B[T], cond *sync.Cond) {
}
}
func (s *state[T]) trySend(value T, buf *circ.B[T]) error {
func (s *state[T]) trySend(value T, buf *queue.Q[T]) error {
s.mu.Lock()
defer s.mu.Unlock()
if s.closed {