summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-mutexes/cond.go
blob: 3d7f21126b3bb3d99e555137774f1d2a8e8093af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package mutexes

import (
	"sync"
)

// Cond is similar to a sync.Cond{}, but
// it encompasses the Mutex{} within itself.
type Cond struct {
	c sync.Cond
	sync.Mutex
}

// See: sync.Cond{}.Wait().
func (c *Cond) Wait() {
	if c.c.L == nil {
		c.c.L = &c.Mutex
	}
	c.c.Wait()
}

// See: sync.Cond{}.Signal().
func (c *Cond) Signal() {
	if c.c.L == nil {
		c.c.L = &c.Mutex
	}
	c.c.Signal()
}

// See: sync.Cond{}.Broadcast().
func (c *Cond) Broadcast() {
	if c.c.L == nil {
		c.c.L = &c.Mutex
	}
	c.c.Broadcast()
}

// RWCond is similar to a sync.Cond{}, but
// it encompasses the RWMutex{} within itself.
type RWCond struct {
	c sync.Cond
	sync.RWMutex
}

// See: sync.Cond{}.Wait().
func (c *RWCond) Wait() {
	if c.c.L == nil {
		c.c.L = &c.RWMutex
	}
	c.c.Wait()
}

// See: sync.Cond{}.Signal().
func (c *RWCond) Signal() {
	if c.c.L == nil {
		c.c.L = &c.RWMutex
	}
	c.c.Signal()
}

// See: sync.Cond{}.Broadcast().
func (c *RWCond) Broadcast() {
	if c.c.L == nil {
		c.c.L = &c.RWMutex
	}
	c.c.Broadcast()
}