Documentation
¶
Index ¶
- Variables
- func DontStop(_ interface{}, _ int) bool
- type PauseNotifier
- type RunState
- type Stepper
- func (st *Stepper) Active() bool
- func (st *Stepper) CheckStates() (cur, req RunState)
- func (st *Stepper) Enter(state RunState)
- func (st *Stepper) Grain() int
- func (st *Stepper) Init() *Stepper
- func (st *Stepper) Pause()
- func (st *Stepper) PauseIfStepsComplete() (pauseNow bool)
- func (st *Stepper) PleaseEnter(state RunState)
- func (st *Stepper) RegisterPauseNotifier(notifier PauseNotifier, pnState interface{})
- func (st *Stepper) RegisterStopChecker(checker StopConditionChecker, cs interface{})
- func (st *Stepper) RequestPause(wait bool)
- func (st *Stepper) RequestState(state RunState, wait bool) RunState
- func (st *Stepper) RequestStop(wait bool)
- func (st *Stepper) SetNSteps(toTake int)
- func (st *Stepper) SetStepGrain(grain int)
- func (st *Stepper) StartStepping(grain int, nSteps int)
- func (st *Stepper) StepPoint(grain int) (stop bool)
- func (st *Stepper) Stop()
- func (st *Stepper) StopRequested() bool
- func (st *Stepper) WaitToGo() RunState
- func (st *Stepper) WaitUntil(state RunState) RunState
- func (st *Stepper) WaitWithTimeout(cond *sync.Cond, secs int)
- type StopConditionChecker
Constants ¶
This section is empty.
Variables ¶
var KiT_RunState = kit.Enums.AddEnum(RunStateN, kit.NotBitFlag, nil)
Functions ¶
Types ¶
type PauseNotifier ¶
type PauseNotifier func(sv interface{})
A PauseNotifier is a callback that will be invoked if the program enters the Paused state. It takes an arbitrary state variable, sv, which is set by RegisterPauseNotifier.
type RunState ¶
type RunState int
const ( Created RunState = iota // this is the initial state, when a stepper is first created. Stopped // execution is stopped. The Stepper is NOT waiting, so running again is basically a restart. The only way to go from Running or Stepping to Stopped is to explicitly call Stop(). Program state will not be preserved once the Stopped state is entered. Paused // execution is paused. The sim is waiting for further instructions, and can continue, or stop. Stepping // the application is running, but will pause if it hits a StepPoint that matches the current StepGrain. Running // the application is running, and will NOT pause at StepPoints. It will pause if a stop has been requested. RunStateN )
type Stepper ¶
type Stepper struct { StateMut sync.Mutex `view:"-" desc:"mutex for RunState"` StateChange *sync.Cond `view:"-" desc:"state change condition variable"` CurState RunState `desc:"current run state"` RequestedState RunState `desc:"requested run state"` StepGrain int `desc:"granularity of one step. No enum type here so clients can define their own"` CondChecker StopConditionChecker `view:"-" desc:"function to test for special stopping conditions"` CheckerState interface{} `view:"-" desc:"arbitrary state information for condition checker"` PauseNotifier PauseNotifier `view:"-" desc:"function to deal with any changes on client side when paused after stepping"` PNState interface{} `view:"-" desc:"arbitrary state information for pause notifier"` Stepping bool `desc:"flag for stepping (as opposed to running"` StepsPerClick int `desc:"number of steps to execute before returning"` StepsRemaining int `desc:"number of steps yet to execute before returning"` WaitTimer chan RunState `desc:"watchdog timer channel"` }
The Stepper struct contains all of the state info for stepping a program, enabling step points. where the running application can be suspended with no loss of state.
func New ¶
func New() *Stepper
New makes a new Stepper. Always call this to create a Stepper, so that initialization will be run correctly.
func (*Stepper) Active ¶
Active checks that the application is either Running or Stepping (neither Paused nor Stopped).
func (*Stepper) CheckStates ¶
CheckStates gets the RunStates, both current and requested.
func (*Stepper) Enter ¶
Enter unconditionally enters the specified RunState, without checking or waiting
func (*Stepper) Init ¶
Init puts everything into a good state before starting a run Init is called automatically by New, and should be called before running again after calling Stop (not Pause). Init should not be called explicitly when creating a new Stepper--the preferred way to initialize is to call New.
func (*Stepper) Pause ¶
func (st *Stepper) Pause()
Pause sets CurState to Paused. Note that the running program may not actually be paused.
func (*Stepper) PauseIfStepsComplete ¶ added in v1.1.12
func (*Stepper) PleaseEnter ¶
PleaseEnter requests that the running application enter the requested state. After calling this, the caller should check to see if the application has changed CurState
func (*Stepper) RegisterPauseNotifier ¶
func (st *Stepper) RegisterPauseNotifier(notifier PauseNotifier, pnState interface{})
RegisterPauseNotifier registers a PauseNotifier callback. A PauseNotifier is not required, but is recommended. As an alternative, the controlling code could poll Stepper state periodically.
func (*Stepper) RegisterStopChecker ¶
func (st *Stepper) RegisterStopChecker(checker StopConditionChecker, cs interface{})
RegisterStopChecker registers a StopConditionChecker callback. This is completely optional: it's fine to not have a StopConditionChecker at all.
func (*Stepper) RequestPause ¶ added in v1.1.12
RequestPause requests that the running program pause, and optionally waits. Really just a wrapper around RequestState.
func (*Stepper) RequestState ¶ added in v1.1.12
RequestState sets RequestedState to the passed in RunState, and will optionally wait for CurState to match the requested RunState. RequestState will wait forever if nothing responds to the request, so it should be used with caution.
func (*Stepper) RequestStop ¶
RequestStop requests that the running program stop, and optionally waits. Really just a wrapper around RequestState.
func (*Stepper) SetNSteps ¶
SetNSteps sets the number of times to go through a StepPoint of the current granularity before actually pausing.
func (*Stepper) SetStepGrain ¶
SetStepGrain sets the internal value of StepGrain to an uninterpreted int. Semantics are up to the client
func (*Stepper) StartStepping ¶
StartStepping enters the Stepping run state.
func (*Stepper) StepPoint ¶
StepPoint checks for possible pause or stop. If the application is: Running: keep going with no further examination of state. Stopped: return true, and the application should return (i.e., stop completely). Stepping: check to see if we should pause (if StepGrain matches, decrement StepsRemaining, stop if <= 0). Paused: wait for state change.
func (*Stepper) Stop ¶
func (st *Stepper) Stop()
Stop sets CurState to Stopped. The running program will exit at the next StepPoint it hits.
func (*Stepper) StopRequested ¶
StopRequested checks for a request to enter the Stopped state.
func (*Stepper) WaitToGo ¶
WaitToGo waits for the application to enter Running, Stepping, or Stopped. It returns the entered state.
type StopConditionChecker ¶
A StopConditionChecker is a callback to check whether an arbitrary condition has been matched. If a StopConditionChecker returns true, the program is suspended with a RunState of Paused, and will remain so until the RunState changes to Stepping, Running, or Stopped.