2018-12-11 22:01:50 +01:00
|
|
|
package frameconn
|
|
|
|
|
|
|
|
import "sync"
|
|
|
|
|
|
|
|
type shutdownFSM struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
mtx sync.Mutex
|
|
|
|
state shutdownFSMState
|
2018-12-11 22:01:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type shutdownFSMState uint32
|
|
|
|
|
|
|
|
const (
|
|
|
|
shutdownStateOpen shutdownFSMState = iota
|
|
|
|
shutdownStateBegin
|
|
|
|
)
|
|
|
|
|
|
|
|
func newShutdownFSM() *shutdownFSM {
|
|
|
|
fsm := &shutdownFSM{
|
2019-03-22 19:41:12 +01:00
|
|
|
state: shutdownStateOpen,
|
2018-12-11 22:01:50 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|