IBR-DTNSuite
0.12
|
#include <Thread.h>
Public Member Functions | |
virtual | ~Thread ()=0 |
void | reset () throw (ThreadException) |
virtual void | setup (void) throw () |
virtual void | run (void)=0 throw () |
virtual void | finally (void) throw () |
bool | isFinalized () throw () |
bool | operator== (const ibrcommon::Thread &other) |
Static Public Member Functions | |
static size_t | getNumberOfProcessors () |
static void | yield (void) |
static void | sleep (time_t timeout) |
static void | concurrency (int level) |
Protected Types | |
enum | THREAD_STATE { THREAD_CREATED = 1 << 0, THREAD_STARTED = 1 << 1, THREAD_INITIALIZED = 1 << 2, THREAD_RUNNING = 1 << 3, THREAD_CANCELLED = 1 << 4, THREAD_FINALIZING = 1 << 5, THREAD_JOINABLE = 1 << 6, THREAD_FINALIZED = 1 << 7 } |
Protected Member Functions | |
Thread (size_t stack=DEFAULT_STACKSIZE) | |
int | kill (int sig) |
void | cancel () throw () |
virtual void | __cancellation ()=0 throw () |
Static Protected Member Functions | |
static bool | equal (pthread_t thread1, pthread_t thread2) |
static void * | __execute__ (void *obj) throw () |
Protected Attributes | |
ibrcommon::ThreadsafeState < THREAD_STATE > | _state |
pthread_t | tid |
size_t | stack |
int | priority |
pthread_attr_t | attr |
bool | _detached |
An abstract class for defining classes that operate as a thread. A derived thread class has a run method that is invoked with the newly created thread context, and can use the derived object to store all member data that needs to be associated with that context. This means the derived object can safely hold thread-specific data that is managed with the life of the object, rather than having to use the clumsy thread-specific data management and access functions found in thread support libraries.
|
protected |
|
protected |
Create a thread object that will have a preset stack size. If 0 is used, then the stack size is os defined/default.
stack | size to use or 0 for default. |
Definition at line 106 of file Thread.cpp.
|
pure virtual |
Destroy thread object, thread-specific data, and execution context.
Definition at line 151 of file Thread.cpp.
References attr.
|
protectedpure virtual |
Implemented in ibrcommon::LogWriter, dtn::daemon::NativeEventLoop, dtn::storage::SQLiteBundleStorage, dtn::dht::DHTNameService, dtn::net::EMailSmtpService, dtn::storage::DataStorage, dtn::net::TCPConnection, dtn::net::TCPConvergenceLayer, dtn::net::DownloadThread, dtn::routing::ProphetRoutingExtension, dtn::api::ClientHandler, dtn::net::DatagramConvergenceLayer, dtn::net::LOWPANConvergenceLayer, dtn::daemon::IndependentComponent, dtn::net::HTTPConvergenceLayer, ibrcommon::Timer, dtn::net::UDPConvergenceLayer, dtn::net::LOWPANConnection, dtn::api::ApiServer, dtn::net::IPNDAgent, dtn::core::FragmentManager, dtn::net::FileMonitor, dtn::routing::EpidemicRoutingExtension, dtn::net::DatagramConnection, dtn::routing::StaticRoutingExtension, ibrcommon::NetLinkManager, dtn::routing::FloodRoutingExtension, dtn::net::FileConvergenceLayer, dtn::routing::NeighborRoutingExtension, ibrcommon::SignalHandler, dtn::net::EMailImapService, ibrcommon::LinkMonitor, dtn::net::WifiP2PManager, and dtn::net::LOWPANConnectionSender.
Referenced by cancel().
|
staticprotected |
static execute thread method
Definition at line 72 of file Thread.cpp.
References _detached, _state, finally(), and run().
Referenced by ibrcommon::JoinableThread::start(), and ibrcommon::DetachedThread::start().
|
protected |
Cancel the running thread context.
Definition at line 181 of file Thread.cpp.
References __cancellation(), _state, ibrcommon::ThreadsafeState< T >::lock(), THREAD_CANCELLED, THREAD_CREATED, THREAD_FINALIZED, THREAD_FINALIZING, THREAD_JOINABLE, THREAD_RUNNING, and ibrcommon::ThreadsafeState< T >::Locked::wait().
Referenced by ibrcommon::JoinableThread::stop(), and ibrcommon::DetachedThread::stop().
|
static |
Set concurrency level of process. This is essentially a portable wrapper for pthread_setconcurrency.
Definition at line 127 of file Thread.cpp.
|
staticprotected |
Determine if two thread identifiers refer to the same thread.
thread1 | to test. |
thread2 | to test. |
Definition at line 210 of file Thread.cpp.
Referenced by ibrcommon::JoinableThread::join(), and operator==().
|
inlinevirtual |
This method is called when the run() method finishes.
Reimplemented in dtn::net::TCPConnection, dtn::api::ClientHandler, dtn::net::LOWPANConnection, and dtn::net::DatagramConnection.
Definition at line 133 of file Thread.h.
Referenced by __execute__().
|
static |
Definition at line 47 of file Thread.cpp.
Referenced by dtn::daemon::Configuration::params().
bool ibrcommon::Thread::isFinalized | ( | ) | ||
throw | ( | |||
) |
Returns true if this thread was started and finalized before.
Definition at line 215 of file Thread.cpp.
References _state, and THREAD_FINALIZED.
|
protected |
sends a signal to this thread
sig |
Definition at line 174 of file Thread.cpp.
References tid.
|
inline |
void ibrcommon::Thread::reset | ( | ) | ||
throw | ( | ThreadException | ||
) |
Reset this thread to initial state
Definition at line 156 of file Thread.cpp.
References _detached, _state, attr, ibrcommon::ThreadsafeState< T >::reset(), THREAD_CREATED, THREAD_FINALIZED, and tid.
|
pure virtual |
Abstract interface for thread context run method.
Implemented in ibrcommon::LogWriter, dtn::daemon::NativeEventLoop, dtn::net::EMailSmtpService, dtn::storage::DataStorage, dtn::net::TCPConnection, dtn::net::DownloadThread, dtn::routing::ProphetRoutingExtension, dtn::api::ClientHandler, ibrcommon::Timer, dtn::daemon::IndependentComponent, dtn::net::LOWPANConnection, dtn::routing::EpidemicRoutingExtension, dtn::net::DatagramConnection, dtn::routing::StaticRoutingExtension, ibrcommon::NetLinkManager, dtn::routing::FloodRoutingExtension, dtn::routing::NeighborRoutingExtension, ibrcommon::LinkMonitor, ibrcommon::SignalHandler, dtn::net::EMailImapService, and dtn::net::LOWPANConnectionSender.
Referenced by __execute__().
|
inlinevirtual |
This method is called before the run.
Reimplemented in dtn::net::TCPConnection, dtn::api::ClientHandler, dtn::net::LOWPANConnection, and dtn::net::DatagramConnection.
|
static |
Sleep current thread for a specified time period.
timeout | to sleep for in milliseconds. |
Definition at line 134 of file Thread.cpp.
Referenced by dtn::api::ApiServer::componentDown(), dtn::net::WifiP2PManager::componentRun(), dtn::net::FileMonitor::componentRun(), dtn::net::HTTPConvergenceLayer::componentRun(), dtn::dht::DHTNameService::componentRun(), dtn::net::WifiP2PManager::connectionEstablished(), main(), and ibrcommon::LinkManager::raiseEvent().
|
static |
Yield execution context of the current thread. This is a static and may be used anywhere.
Definition at line 116 of file Thread.cpp.
Referenced by dtn::net::IPNDAgent::componentRun(), dtn::net::UDPConvergenceLayer::componentRun(), dtn::api::ApiServer::componentRun(), dtn::net::HTTPConvergenceLayer::componentRun(), dtn::net::LOWPANConvergenceLayer::componentRun(), dtn::net::DatagramConvergenceLayer::componentRun(), dtn::net::TCPConvergenceLayer::componentRun(), ibrcommon::LinkMonitor::run(), dtn::routing::NeighborRoutingExtension::run(), dtn::routing::FloodRoutingExtension::run(), dtn::routing::StaticRoutingExtension::run(), dtn::routing::EpidemicRoutingExtension::run(), ibrcommon::Timer::run(), dtn::net::DownloadThread::run(), and dtn::net::TCPConnection::run().
|
protected |
Definition at line 86 of file Thread.h.
Referenced by __execute__(), and reset().
|
protected |
Definition at line 71 of file Thread.h.
Referenced by __execute__(), cancel(), isFinalized(), ibrcommon::JoinableThread::isRunning(), ibrcommon::JoinableThread::join(), reset(), and ibrcommon::JoinableThread::~JoinableThread().
|
protected |
|
protected |
Definition at line 74 of file Thread.h.
Referenced by ibrcommon::JoinableThread::join(), kill(), operator==(), and reset().