|
LRAUV
revA
|
A ThreadHandler is a Handler which runs in its own thread. More...
#include <ThreadHandler.h>


Public Member Functions | |
| ThreadHandler (Component &inComponent, const Str &name, bool idleThread) | |
| Constructor. More... | |
| virtual | ~ThreadHandler () |
| Destructor. More... | |
| virtual void | run () |
| Overrides Handler::run(). More... | |
| void | cleanup (void) |
| A member function for the cleanup callback (called from threadCleanup) More... | |
| virtual void | runInThread () |
| The new replacement for Handler::run() which runs in the thread., Run from the static threadEntryPoint. More... | |
| virtual bool | continueLoop (void) |
| Evaluates additional thread-specific continue conditions. More... | |
| virtual void | shutdown (void) |
| Cleanup the component (typically called from outside component) More... | |
| void | exitThread (void) |
| Called by the thread to end itself (pthread_Exit) More... | |
| void | cancelThread (void) |
| A "soft exit", requests the thread end on next loop. More... | |
| void | joinThread (void) |
| Join the thread. More... | |
| void | killThread (void) |
| End the thread immediately (uses pthread_cancel) More... | |
| const pthread_t & | getThreadId () |
Public Member Functions inherited from Handler | |
| Handler (Component &inComponent, const Str &name, bool idleThread=false) | |
| Constructor. More... | |
| virtual | ~Handler () |
| Destructor. More... | |
| virtual void | runOnce (void) |
| Virtual function run only on first iteration of handler. More... | |
| virtual void | runBetween (void) |
| Virtual function run after the first iteration of the handler. More... | |
| virtual bool | isRunning (void) |
| True if handler is running. More... | |
| const Str & | getName () |
| void | setAsLogHandler (bool logHandler) |
| void | setAsControlLoopHandler (bool controlLoopHandler) |
Static Public Member Functions | |
| static int | PthreadJoinTimeout (pthread_t wid, unsigned int msecs, Component &component) |
| static void * | ThreadEntryPoint (void *me) |
| The entry point for the new thread. A static function. More... | |
| static void | ThreadCleanup (void *me) |
| A static entry point for a cleanup callback. More... | |
Static Public Member Functions inherited from Handler | |
| static bool | IsFastSimAllowed () |
Protected Attributes | |
| bool | cancelled_ |
| Keeps track of the "cancelled" signal from cancelThread. More... | |
Protected Attributes inherited from Handler | |
| Component & | component_ |
| The "handled" Component. More... | |
| Timestamp | componentStartTime_ |
| Keep track of when the component is supposed to start next. More... | |
| Logger | logger_ |
| PCaller * | pCaller_ |
| Used for making protected calls. More... | |
| bool | running_ |
Private Attributes | |
| pthread_t | threadID_ |
| The thread ID. More... | |
| pthread_attr_t | threadAttributes_ |
| the thread attributes More... | |
Additional Inherited Members | |
Static Protected Attributes inherited from Handler | |
| static const Timespan | SMALL_INTERVAL = Timespan::FromMicros( 800 ) |
A ThreadHandler is a Handler which runs in its own thread.
This is the primary abstraction for a "thread" in this software. When wrapped around a Component, this handler spins off a separate thread and executes the component in it.
Constructor.
| inComponent | Component being handled, passed to Handler |
| name | Name for this (fed to its logger_) |
| idleThread | true if the thread wrapper for the component should be ile priority |
References threadAttributes_.
|
virtual |
| void ThreadHandler::cancelThread | ( | void | ) |
A "soft exit", requests the thread end on next loop.
End this thread.
References cancelled_, Syslog::INFO, Handler::logger_, and Logger::syslog().
Referenced by runInThread(), and shutdown().
| void ThreadHandler::cleanup | ( | void | ) |
A member function for the cleanup callback (called from threadCleanup)
References Handler::component_, and Component::uninitialize().
|
virtual |
Evaluates additional thread-specific continue conditions.
Supplemental end conditions.
Reimplemented from Handler.
References cancelled_, and Handler::continueLoop().
| void ThreadHandler::exitThread | ( | void | ) |
Called by the thread to end itself (pthread_Exit)
Exit this thread.
References threadID_.
Referenced by shutdown().
|
inline |
References threadID_.
| void ThreadHandler::joinThread | ( | void | ) |
Join the thread.
References Handler::component_, PthreadJoinTimeout(), and threadID_.
Referenced by shutdown(), and ~ThreadHandler().
| void ThreadHandler::killThread | ( | void | ) |
End the thread immediately (uses pthread_cancel)
Send a kill signal to thread.
exitThread waits for the component to yield before ending the thread. killThread interrupts the thread.
References threadID_.
Referenced by ~ThreadHandler().
|
static |
References Str::cStr(), WaitData::done_, get_ticks(), Component::getLogger(), Component::getName(), join_timeout_helper(), PTHREAD_JOIN_POLL_INTERVAL, Component::segfault(), and sleep_msecs().
Referenced by joinThread().
|
virtual |
Overrides Handler::run().
Launch thread, run component in that thread.
Contains the actual launch of the new thread, then returns.
Reimplemented from Handler.
References threadAttributes_, ThreadEntryPoint(), and threadID_.
|
virtual |
The new replacement for Handler::run() which runs in the thread., Run from the static threadEntryPoint.
This is essentially "run", but it happens in the thread.
This in turn runs Handler::run() with some thread-specific entry and exit code.
References cancelThread(), Syslog::INFO, Handler::logger_, Handler::run(), Logger::syslog(), and ThreadCleanup().
|
virtual |
Cleanup the component (typically called from outside component)
Generic call, inherited from Handler to stop the component.
In this case, means "stop and reap the thread"
Reimplemented from Handler.
References cancelThread(), exitThread(), joinThread(), Handler::shutdown(), and threadID_.
|
static |
A static entry point for a cleanup callback.
Referenced by runInThread().
|
static |
The entry point for the new thread. A static function.
This is my static thread entry point.
Referenced by run().
|
protected |
Keeps track of the "cancelled" signal from cancelThread.
Referenced by cancelThread(), and continueLoop().
|
private |
the thread attributes
Referenced by run(), ThreadHandler(), and ~ThreadHandler().
|
private |
The thread ID.
Referenced by exitThread(), getThreadId(), joinThread(), killThread(), run(), and shutdown().