2024-01-22 15:33:51 +01:00
|
|
|
package mutexes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Cond is similar to a sync.Cond{}, but
|
|
|
|
// it encompasses the Mutex{} within itself.
|
|
|
|
type Cond struct {
|
2024-06-21 18:35:32 +02:00
|
|
|
c sync.Cond
|
2024-01-22 15:33:51 +01:00
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
// See: sync.Cond{}.Wait().
|
|
|
|
func (c *Cond) Wait() {
|
2024-06-21 18:35:32 +02:00
|
|
|
if c.c.L == nil {
|
|
|
|
c.c.L = &c.Mutex
|
|
|
|
}
|
|
|
|
c.c.Wait()
|
2024-01-22 15:33:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// See: sync.Cond{}.Signal().
|
2024-06-21 18:35:32 +02:00
|
|
|
func (c *Cond) Signal() {
|
|
|
|
if c.c.L == nil {
|
|
|
|
c.c.L = &c.Mutex
|
|
|
|
}
|
|
|
|
c.c.Signal()
|
|
|
|
}
|
2024-01-22 15:33:51 +01:00
|
|
|
|
|
|
|
// See: sync.Cond{}.Broadcast().
|
2024-06-21 18:35:32 +02:00
|
|
|
func (c *Cond) Broadcast() {
|
|
|
|
if c.c.L == nil {
|
|
|
|
c.c.L = &c.Mutex
|
|
|
|
}
|
|
|
|
c.c.Broadcast()
|
|
|
|
}
|
2024-01-22 15:33:51 +01:00
|
|
|
|
|
|
|
// RWCond is similar to a sync.Cond{}, but
|
|
|
|
// it encompasses the RWMutex{} within itself.
|
|
|
|
type RWCond struct {
|
2024-06-21 18:35:32 +02:00
|
|
|
c sync.Cond
|
2024-01-22 15:33:51 +01:00
|
|
|
sync.RWMutex
|
|
|
|
}
|
|
|
|
|
|
|
|
// See: sync.Cond{}.Wait().
|
|
|
|
func (c *RWCond) Wait() {
|
2024-06-21 18:35:32 +02:00
|
|
|
if c.c.L == nil {
|
|
|
|
c.c.L = &c.RWMutex
|
|
|
|
}
|
|
|
|
c.c.Wait()
|
2024-01-22 15:33:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// See: sync.Cond{}.Signal().
|
2024-06-21 18:35:32 +02:00
|
|
|
func (c *RWCond) Signal() {
|
|
|
|
if c.c.L == nil {
|
|
|
|
c.c.L = &c.RWMutex
|
|
|
|
}
|
|
|
|
c.c.Signal()
|
2024-01-22 15:33:51 +01:00
|
|
|
}
|
|
|
|
|
2024-06-21 18:35:32 +02:00
|
|
|
// See: sync.Cond{}.Broadcast().
|
|
|
|
func (c *RWCond) Broadcast() {
|
|
|
|
if c.c.L == nil {
|
|
|
|
c.c.L = &c.RWMutex
|
|
|
|
}
|
|
|
|
c.c.Broadcast()
|
2024-01-22 15:33:51 +01:00
|
|
|
}
|