Files
game-driver/internal/common/pause.go
2025-03-13 19:18:10 +08:00

54 lines
696 B
Go

package common
import "sync"
// CtrlWait 待机暂停控制器
type CtrlWait struct {
C chan int8
// 状态
s bool
m sync.RWMutex
}
// Pause 暂停
func (c *CtrlWait) Pause() {
c.m.RLock()
defer c.m.RUnlock()
if c.s {
c.C <- 1
}
}
// Resume 恢复
func (c *CtrlWait) Resume() {
c.m.RLock()
defer c.m.RUnlock()
if c.s {
c.C <- 0
}
}
func (c *CtrlWait) Open() {
c.m.Lock()
defer c.m.Unlock()
c.s = true
}
func (c *CtrlWait) Close() {
c.m.Lock()
defer c.m.Unlock()
c.s = false
}
// NewCtrlWait 创建一个控制等待
func NewCtrlWait() *CtrlWait {
return &CtrlWait{
C: make(chan int8),
s: false,
}
}
// PassCtrl 全局控制等待
var PassCtrl = NewCtrlWait()