|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Minimal cooperative-shutdown base class for objects that run a worker thread. More...
#include <ThreadManager.h>
Public Member Functions | |
| Runnable () | |
| Initialise flags: not running, allowed to continue. | |
| virtual | ~Runnable () |
| Destructor requests a stop (with the default timeout) before destruction proceeds. | |
| virtual bool | stop (uint32 timeout=200) |
| Ask the worker loop to finish and wait for it to do so. | |
Protected Attributes | |
| uint32 | threadID |
| ThreadManager slot ID of the worker thread (0 until known). | |
| bool | shouldContinue |
| Loop-continuation flag; cleared by stop(). | |
| bool | isRunning |
| Set by the worker while its loop is active. | |
Minimal cooperative-shutdown base class for objects that run a worker thread.
A subclass runs its loop while shouldContinue is true and sets isRunning around the loop body. stop() flips shouldContinue and then spin-waits (5 ms steps) for the loop to observe it and clear isRunning. This is cooperative: the thread is never forcibly killed by stop(); a loop that blocks indefinitely will simply cause stop() to time out.
Definition at line 153 of file ThreadManager.h.
|
inline |
Initialise flags: not running, allowed to continue.
Definition at line 156 of file ThreadManager.h.
References isRunning, shouldContinue, and threadID.
|
inlinevirtual |
Destructor requests a stop (with the default timeout) before destruction proceeds.
Definition at line 158 of file ThreadManager.h.
References stop().
|
inlinevirtual |
Ask the worker loop to finish and wait for it to do so.
| timeout | Maximum time to wait, in milliseconds (default 200). |
Definition at line 166 of file ThreadManager.h.
References isRunning, LOG_SYSTEM, LogPrint, shouldContinue, cmlabs::utils::Sleep(), and threadID.
Referenced by cmlabs::NetworkConnection::disconnectInternal(), cmlabs::PsySpace::shutdown(), cmlabs::ThreadManager::shutdown(), cmlabs::RequestClient::~RequestClient(), cmlabs::RequestExecutor::~RequestExecutor(), cmlabs::RequestGateway::~RequestGateway(), and ~Runnable().
|
protected |
Set by the worker while its loop is active.
Definition at line 182 of file ThreadManager.h.
Referenced by cmlabs::RequestClient::RequestClient(), cmlabs::RequestExecutor::RequestExecutor(), cmlabs::RequestGateway::RequestGateway(), cmlabs::NetworkConnection::run(), cmlabs::RequestClient::run(), cmlabs::RequestExecutor::run(), cmlabs::RequestGateway::runClient(), cmlabs::RequestGateway::runExec(), Runnable(), cmlabs::PsySpace::shutdown(), stop(), cmlabs::ThreadManager::ThreadManager(), and cmlabs::ThreadManager::threadMonitoring().
|
protected |
Loop-continuation flag; cleared by stop().
Definition at line 181 of file ThreadManager.h.
Referenced by cmlabs::RequestGateway::init(), cmlabs::TestRequestExecutor::longRequestRun(), cmlabs::RequestClient::RequestClient(), cmlabs::RequestExecutor::RequestExecutor(), cmlabs::RequestGateway::RequestGateway(), cmlabs::NetworkConnection::run(), cmlabs::RequestClient::run(), cmlabs::RequestExecutor::run(), cmlabs::RequestGateway::runClient(), cmlabs::RequestGateway::runExec(), Runnable(), cmlabs::TestRequestExecutor::shortRequestRun(), stop(), cmlabs::TestRequestExecutor::TestRequestExecutor(), cmlabs::ThreadManager::ThreadManager(), cmlabs::ThreadManager::threadMonitoring(), and cmlabs::RequestGateway::~RequestGateway().
|
protected |
ThreadManager slot ID of the worker thread (0 until known).
Definition at line 180 of file ThreadManager.h.
Referenced by cmlabs::PsySpace::connect(), cmlabs::RequestGateway::init(), cmlabs::TCPListener::init(), cmlabs::RequestGateway::RequestGateway(), Runnable(), stop(), cmlabs::TCPListener::TCPListener(), cmlabs::RequestGateway::~RequestGateway(), and cmlabs::TCPListener::~TCPListener().