| 12345678910111213141516171819202122232425262728293031 |
- package common
- import "sync"
- type Condition interface {
- Wait()
- Notify()
- NotifyAll()
- }
- type condition struct {
- sync.Mutex
- c *sync.Cond
- }
- func NewCond() Condition {
- c := new(condition)
- c.c = sync.NewCond(c)
- return c
- }
- func (c *condition) Wait() {
- c.Lock()
- defer c.Unlock()
- c.c.Wait()
- }
- func (c *condition) Notify() {
- c.c.Signal()
- }
- func (c *condition) NotifyAll() {
- c.c.Broadcast()
- }
|