Develop Biology
The language of life
|
#include <Threaded.h>
Public Types | |
typedef pid_t | ThreadId |
Public Member Functions | |
Threaded () | |
virtual | ~Threaded () |
virtual ThreadId | GetThreadId () |
virtual bool | IsRunning () |
virtual void | Sleep (TimeUS us) |
virtual bool | Start () |
virtual bool | Stop () |
virtual bool | Work () |
Public Member Functions inherited from bio::ThreadSafe | |
ThreadSafe () | |
ThreadSafe (const ThreadSafe &toCopy) | |
virtual | ~ThreadSafe () |
void | LockThread () const |
void | UnlockThread () const |
Static Public Member Functions | |
static ThreadId | InvalidThreadId () |
Protected Member Functions | |
virtual void | RequestStop () |
Static Protected Member Functions | |
static void * | Worker (void *arg) |
Protected Attributes | |
bool | m_created |
ThreadId | m_id |
bool | m_running |
bool | m_stopRequested |
Threaded classes are a wrapper around whatever thread interface the system is using. This class moves whatever Work() you need to do into a new thread with a simple wrapper that is OS & c++ version independent.
NOTE: we're currently only supporting threading on c++11 and greater and on linux using c++98 on. We may or may not ever support c++98 threading on windows, etc. TODO: does pthread work on Apple and BSD?
NOTE: YOU MUST CALL STOP BEFORE DESTROYING *this!!!!
Definition at line 52 of file Threaded.h.
typedef pid_t bio::Threaded::ThreadId |
Definition at line 57 of file Threaded.h.
bio::Threaded::Threaded | ( | ) |
YOU MUST CALL STOP BEFORE DESTROYING *this!!!!
Definition at line 37 of file Threaded.cpp.
|
virtual |
Definition at line 56 of file Threaded.cpp.
References BIO_ASSERT, and m_running.
|
virtual |
Definition at line 102 of file Threaded.cpp.
References BIO_SANITIZE, InvalidThreadId(), and m_id.
|
inlinestatic |
Definition at line 65 of file Threaded.h.
Referenced by GetThreadId().
|
virtual |
Definition at line 61 of file Threaded.cpp.
References bio::ThreadSafe::LockThread(), m_running, and bio::ThreadSafe::UnlockThread().
|
protectedvirtual |
Sets m_stopRequested to true.
Definition at line 69 of file Threaded.cpp.
References bio::ThreadSafe::LockThread(), m_stopRequested, and bio::ThreadSafe::UnlockThread().
Referenced by Stop().
|
virtual |
Release thread processing for us microseconds.
us |
Definition at line 170 of file Threaded.cpp.
|
virtual |
Starts our thread, which will continuously call Work() until Stop()ed (or Work() exits).
Definition at line 114 of file Threaded.cpp.
References BIO_SANITIZE, bio::ThreadSafe::LockThread(), m_created, m_running, bio::ThreadSafe::UnlockThread(), and Worker().
|
virtual |
Instructs our thread to stop calling Work() and joins our thread.
Definition at line 139 of file Threaded.cpp.
References BIO_SANITIZE, bio::ThreadSafe::LockThread(), m_created, m_running, m_stopRequested, RequestStop(), and bio::ThreadSafe::UnlockThread().
|
inlinevirtual |
Does the actual work. Will be called repeatedly until either: Stop() is called OR this method returns false. So, just return false when you want to stop being a thread. You may want to Sleep() (below) after you Work() ;)
Reimplemented in bio::physical::ThreadedPeriodic.
Definition at line 89 of file Threaded.h.
Referenced by Worker().
|
staticprotected |
arg | a Threaded* |
Definition at line 76 of file Threaded.cpp.
References BIO_SANITIZE, bio::ThreadSafe::LockThread(), m_running, m_stopRequested, bio::ThreadSafe::UnlockThread(), and Work().
Referenced by Start().
|
protected |
Definition at line 141 of file Threaded.h.
|
protected |
Definition at line 130 of file Threaded.h.
Referenced by GetThreadId().
|
protected |
Definition at line 142 of file Threaded.h.
Referenced by ~Threaded(), IsRunning(), Start(), Stop(), and Worker().
|
protected |
Definition at line 143 of file Threaded.h.
Referenced by RequestStop(), Stop(), and Worker().