mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Stoppable, make stop() require call to start()
This commit is contained in:
@@ -265,6 +265,7 @@ protected:
|
|||||||
char const* m_name;
|
char const* m_name;
|
||||||
RootStoppable& m_root;
|
RootStoppable& m_root;
|
||||||
Child m_child;
|
Child m_child;
|
||||||
|
Atomic <int> m_started;
|
||||||
bool volatile m_stopped;
|
bool volatile m_stopped;
|
||||||
bool volatile m_childrenStopped;
|
bool volatile m_childrenStopped;
|
||||||
Children m_children;
|
Children m_children;
|
||||||
@@ -301,6 +302,8 @@ public:
|
|||||||
/** Notify a root stoppable and children to stop, and block until stopped.
|
/** Notify a root stoppable and children to stop, and block until stopped.
|
||||||
Has no effect if the stoppable was already notified.
|
Has no effect if the stoppable was already notified.
|
||||||
This blocks until the stoppable and all of its children have stopped.
|
This blocks until the stoppable and all of its children have stopped.
|
||||||
|
Undefined behavior results if stop() is called without a previous call
|
||||||
|
to start().
|
||||||
Thread safety:
|
Thread safety:
|
||||||
Safe to call from any thread not associated with a Stoppable.
|
Safe to call from any thread not associated with a Stoppable.
|
||||||
*/
|
*/
|
||||||
@@ -316,7 +319,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Atomic <int> m_prepared;
|
Atomic <int> m_prepared;
|
||||||
Atomic <int> m_started;
|
|
||||||
Atomic <int> m_calledStop;
|
Atomic <int> m_calledStop;
|
||||||
Atomic <int> m_calledStopAsync;
|
Atomic <int> m_calledStopAsync;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ Stoppable::Stoppable (char const* name, Stoppable& parent)
|
|||||||
Stoppable::~Stoppable ()
|
Stoppable::~Stoppable ()
|
||||||
{
|
{
|
||||||
// Children must be stopped.
|
// Children must be stopped.
|
||||||
bassert (m_childrenStopped);
|
bassert (m_started.get() == 0 || m_childrenStopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stoppable::isStopping() const
|
bool Stoppable::isStopping() const
|
||||||
@@ -177,6 +177,9 @@ void RootStoppable::start ()
|
|||||||
|
|
||||||
void RootStoppable::stop (Journal journal)
|
void RootStoppable::stop (Journal journal)
|
||||||
{
|
{
|
||||||
|
// Must have a prior call to start()
|
||||||
|
bassert (m_started.get() != 0);
|
||||||
|
|
||||||
if (! m_calledStop.compareAndSetBool (1, 0))
|
if (! m_calledStop.compareAndSetBool (1, 0))
|
||||||
{
|
{
|
||||||
journal.warning << "Stoppable::stop called again";
|
journal.warning << "Stoppable::stop called again";
|
||||||
|
|||||||
Reference in New Issue
Block a user