blob: 00d31641c6b86393f7b8440e460530df6baeb64a (
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
|
// Copyright (C) 2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
package typedsync
import (
"sync"
)
// Cond is a type-safe equivalent of the standard library's sync.Cond.
//
// See the [sync.Cond documentation] for full details.
//
// [sync.Cond documentation]: https://pkg.go.dev/sync#Cond
type Cond[T Locker] struct {
L T
inner sync.Cond
}
func NewCond[T Locker](l T) *Cond[T] {
return &Cond[T]{L: l}
}
func (c *Cond[T]) Broadcast() {
c.inner.L = c.L
c.inner.Broadcast()
}
func (c *Cond[T]) Signal() {
c.inner.L = c.L
c.inner.Signal()
}
func (c *Cond[T]) Wait() {
c.inner.L = c.L
c.inner.Wait()
}
|