Unlock() before panic() when already closed.

This commit is contained in:
Sam Fredrickson 2023-07-10 10:55:25 -07:00
parent 9d1228988d
commit a20c8908de
3 changed files with 3 additions and 0 deletions

View File

@ -73,6 +73,7 @@ type state[T any] struct {
func (s *state[T]) Close() { func (s *state[T]) Close() {
s.mu.Lock() s.mu.Lock()
if s.closed { if s.closed {
s.mu.Unlock()
panic("close of closed queue") panic("close of closed queue")
} }
s.closed = true s.closed = true

View File

@ -93,6 +93,7 @@ type state[P constraints.Integer, T any] struct {
func (s *state[P, T]) Close() { func (s *state[P, T]) Close() {
s.mu.Lock() s.mu.Lock()
if s.closed { if s.closed {
s.mu.Unlock()
panic("close of closed queue") panic("close of closed queue")
} }
s.closed = true s.closed = true

View File

@ -61,6 +61,7 @@ type state[P constraints.Ordered, T any] struct {
func (s *state[P, T]) Close() { func (s *state[P, T]) Close() {
s.mu.Lock() s.mu.Lock()
if s.closed { if s.closed {
s.mu.Unlock()
panic("close of closed queue") panic("close of closed queue")
} }
s.closed = true s.closed = true