zrepl/rpc/dataconn/frameconn/frameconn_shutdown_fsm.go

31 lines
578 B
Go
Raw Permalink Normal View History

package frameconn
import "sync"
type shutdownFSM struct {
2019-03-22 19:41:12 +01:00
mtx sync.Mutex
state shutdownFSMState
}
type shutdownFSMState uint32
const (
// zero value is important
shutdownStateOpen shutdownFSMState = iota
shutdownStateBegin
)
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
}