// Suspend/resume support for POSIX platforms // Protocol: // // a thread starts in SR_RUNNING // // SR_RUNNING can go to // * SR_SUSPEND_REQUEST when the WatcherThread wants to suspend it // SR_SUSPEND_REQUEST can go to // * SR_RUNNING if WatcherThread decides it waited for SR_SUSPENDED too long (timeout) // * SR_SUSPENDED if the stopped thread receives the signal and switches state // SR_SUSPENDED can go to // * SR_WAKEUP_REQUEST when the WatcherThread has done the work and wants to resume // SR_WAKEUP_REQUEST can go to // * SR_RUNNING when the stopped thread receives the signal // * SR_WAKEUP_REQUEST on timeout (resend the signal and try again) class SuspendResume { public: enum State {
SR_RUNNING,
SR_SUSPEND_REQUEST,
SR_SUSPENDED,
SR_WAKEUP_REQUEST
};
private: volatile State _state;
private: /* try to switch state from state "from" to state "to" *returnsthestatesetafterthemethodiscomplete
*/
State switch_state(State from, State to);
public:
SuspendResume() : _state(SR_RUNNING) { }
State state() const { return _state; }
State request_suspend() { return switch_state(SR_RUNNING, SR_SUSPEND_REQUEST);
}
State cancel_suspend() { return switch_state(SR_SUSPEND_REQUEST, SR_RUNNING);
}
State suspended() { return switch_state(SR_SUSPEND_REQUEST, SR_SUSPENDED);
}
State request_wakeup() { return switch_state(SR_SUSPENDED, SR_WAKEUP_REQUEST);
}
State running() { return switch_state(SR_WAKEUP_REQUEST, SR_RUNNING);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.