mirror of
https://github.com/zrepl/zrepl.git
synced 2025-02-10 07:29:53 +01:00
38 lines
683 B
Go
38 lines
683 B
Go
|
package frameconn
|
||
|
|
||
|
import "sync"
|
||
|
|
||
|
type shutdownFSM struct {
|
||
|
mtx sync.Mutex
|
||
|
state shutdownFSMState
|
||
|
}
|
||
|
|
||
|
type shutdownFSMState uint32
|
||
|
|
||
|
const (
|
||
|
shutdownStateOpen shutdownFSMState = iota
|
||
|
shutdownStateBegin
|
||
|
)
|
||
|
|
||
|
func newShutdownFSM() *shutdownFSM {
|
||
|
fsm := &shutdownFSM{
|
||
|
state: shutdownStateOpen,
|
||
|
}
|
||
|
return fsm
|
||
|
}
|
||
|
|
||
|
func (f *shutdownFSM) Begin() (thisCallStartedShutdown bool) {
|
||
|
f.mtx.Lock()
|
||
|
defer f.mtx.Unlock()
|
||
|
thisCallStartedShutdown = f.state != shutdownStateOpen
|
||
|
f.state = shutdownStateBegin
|
||
|
return thisCallStartedShutdown
|
||
|
}
|
||
|
|
||
|
func (f *shutdownFSM) IsShuttingDown() bool {
|
||
|
f.mtx.Lock()
|
||
|
defer f.mtx.Unlock()
|
||
|
return f.state != shutdownStateOpen
|
||
|
}
|
||
|
|