IBR-DTNSuite
0.8
|
#include <Thread.h>
Public Member Functions | |
virtual | ~Thread ()=0 |
virtual void | setup (void) |
virtual void | run (void)=0 |
virtual void | finally (void) |
void | detach (void) |
bool | operator== (const ibrcommon::Thread &other) |
Static Public Member Functions | |
static void | yield (void) |
static void | sleep (size_t timeout) |
static void | exit (void) |
static void | concurrency (int level) |
Protected Types | |
enum | THREAD_STATE { THREAD_INITIALIZED = 1 << 0, THREAD_PREPARE = 1 << 1, THREAD_SETUP = 1 << 2, THREAD_RUNNING = 1 << 3, THREAD_CANCELLED = 1 << 4, THREAD_FINALIZING = 1 << 5, THREAD_FINALIZED = 1 << 6, THREAD_JOINED = 1 << 7, THREAD_ERROR = 1 << 8 } |
Protected Member Functions | |
Thread (size_t stack=DEFAULT_STACKSIZE, bool delete_on_exit=false) | |
int | kill (int sig) |
void | cancel () throw (ThreadException) |
virtual void | __cancellation ()=0 |
Static Protected Member Functions | |
static bool | equal (pthread_t thread1, pthread_t thread2) |
static void * | exec_thread (void *obj) |
static void | finalize_thread (void *obj) |
Protected Attributes | |
ibrcommon::ThreadsafeState < THREAD_STATE > | _state |
pthread_t | tid |
size_t | stack |
int | priority |
pthread_attr_t | attr |
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.
enum ibrcommon::Thread::THREAD_STATE [protected] |
ibrcommon::Thread::Thread | ( | size_t | stack = DEFAULT_STACKSIZE , |
bool | delete_on_exit = false |
||
) | [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 105 of file Thread.cpp.
References attr.
ibrcommon::Thread::~Thread | ( | ) | [pure virtual] |
Destroy thread object, thread-specific data, and execution context.
Definition at line 143 of file Thread.cpp.
References attr.
virtual void ibrcommon::Thread::__cancellation | ( | ) | [protected, pure virtual] |
Implemented in dtn::net::TCPConvergenceLayer, dtn::routing::ProphetRoutingExtension, dtn::net::DatagramConvergenceLayer, dtn::dht::DHTNameService, dtn::net::TCPConnection, dtn::storage::SQLiteBundleStorage, dtn::net::DownloadThread, dtn::storage::DataStorage, dtn::api::ClientHandler, dtn::net::HTTPConvergenceLayer, ibrcommon::NetLinkManager, ibrcommon::NetLink3Manager, dtn::net::LOWPANConvergenceLayer, ibrcommon::Timer, dtn::daemon::IndependentComponent, dtn::api::ApiServer, dtn::net::LOWPANConnection, dtn::net::UDPConvergenceLayer, dtn::net::DatagramConnection, dtn::net::IPNDAgent, dtn::routing::EpidemicRoutingExtension, dtn::net::FileConvergenceLayer, dtn::routing::StaticRoutingExtension, dtn::routing::FloodRoutingExtension, dtn::net::FileMonitor, dtn::routing::NeighborRoutingExtension, dtn::core::FragmentManager, and dtn::net::LOWPANConnectionSender.
Referenced by cancel().
void ibrcommon::Thread::cancel | ( | ) | throw (ThreadException) [protected] |
Cancel the running thread context.
Definition at line 164 of file Thread.cpp.
References __cancellation(), _state, ibrcommon::ThreadsafeState< T >::lock(), THREAD_CANCELLED, THREAD_ERROR, THREAD_FINALIZED, THREAD_INITIALIZED, THREAD_JOINED, THREAD_PREPARE, THREAD_RUNNING, THREAD_SETUP, and ibrcommon::ThreadsafeState< T >::Locked::wait().
Referenced by ibrcommon::JoinableThread::stop(), and ibrcommon::DetachedThread::stop().
void ibrcommon::Thread::concurrency | ( | int | level | ) | [static] |
Set concurrency level of process. This is essentially a portable wrapper for pthread_setconcurrency.
Definition at line 122 of file Thread.cpp.
void ibrcommon::Thread::detach | ( | void | ) |
bool ibrcommon::Thread::equal | ( | pthread_t | thread1, |
pthread_t | thread2 | ||
) | [static, protected] |
Determine if two thread identifiers refer to the same thread.
thread1 | to test. |
thread2 | to test. |
Definition at line 195 of file Thread.cpp.
Referenced by ibrcommon::JoinableThread::join(), and operator==().
void * ibrcommon::Thread::exec_thread | ( | void * | obj | ) | [static, protected] |
static execute thread method
Definition at line 50 of file Thread.cpp.
References exit(), finalize_thread(), IBRCOMMON_LOGGER_DEBUG, IBRCOMMON_LOGGER_ENDL, THREAD_PREPARE, THREAD_RUNNING, and THREAD_SETUP.
Referenced by ibrcommon::JoinableThread::start(), and ibrcommon::DetachedThread::start().
void ibrcommon::Thread::exit | ( | void | ) | [static] |
Exit the thread context.
Definition at line 153 of file Thread.cpp.
Referenced by exec_thread(), and ibrcommon::JoinableThread::join().
void ibrcommon::Thread::finalize_thread | ( | void * | obj | ) | [static, protected] |
this method finalizes a thread. If the thread is self-deleting, the object will be invalid after exection.
Definition at line 25 of file Thread.cpp.
References _state, finally(), THREAD_FINALIZED, and THREAD_FINALIZING.
Referenced by exec_thread().
virtual void ibrcommon::Thread::finally | ( | void | ) | [inline, virtual] |
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 110 of file Thread.h.
Referenced by finalize_thread().
int ibrcommon::Thread::kill | ( | int | sig | ) | [protected] |
sends a signal to this thread
sig |
Definition at line 158 of file Thread.cpp.
References tid.
bool ibrcommon::Thread::operator== | ( | const ibrcommon::Thread & | other | ) | [inline] |
virtual void ibrcommon::Thread::run | ( | void | ) | [pure virtual] |
Abstract interface for thread context run method.
Implemented in dtn::routing::ProphetRoutingExtension, dtn::net::TCPConnection, dtn::net::DownloadThread, dtn::storage::DataStorage, dtn::api::ClientHandler, ibrcommon::NetLinkManager, ibrcommon::NetLink3Manager, ibrcommon::Timer, dtn::daemon::IndependentComponent, dtn::net::LOWPANConnection, dtn::net::DatagramConnection, dtn::routing::EpidemicRoutingExtension, dtn::routing::StaticRoutingExtension, dtn::routing::FloodRoutingExtension, dtn::routing::NeighborRoutingExtension, and dtn::net::LOWPANConnectionSender.
virtual void ibrcommon::Thread::setup | ( | void | ) | [inline, virtual] |
This method is called before the run.
Reimplemented in dtn::net::TCPConnection, dtn::api::ClientHandler, dtn::net::LOWPANConnection, and dtn::net::DatagramConnection.
void ibrcommon::Thread::sleep | ( | size_t | timeout | ) | [static] |
Sleep current thread for a specified time period.
timeout | to sleep for in milliseconds. |
Definition at line 129 of file Thread.cpp.
Referenced by dtn::api::ApiServer::componentDown(), dtn::net::FileMonitor::componentRun(), and dtn::net::HTTPConvergenceLayer::componentRun().
void ibrcommon::Thread::yield | ( | void | ) | [static] |
Yield execution context of the current thread. This is a static and may be used anywhere.
Definition at line 111 of file Thread.cpp.
Referenced by dtn::net::IPNDAgent::componentRun(), dtn::net::UDPConvergenceLayer::componentRun(), dtn::net::LOWPANConvergenceLayer::componentRun(), dtn::api::ApiServer::componentRun(), dtn::net::HTTPConvergenceLayer::componentRun(), dtn::net::DatagramConvergenceLayer::componentRun(), dtn::net::TCPConvergenceLayer::componentRun(), 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().
Definition at line 58 of file Thread.h.
Referenced by cancel(), finalize_thread(), ibrcommon::JoinableThread::isRunning(), ibrcommon::JoinableThread::join(), and ibrcommon::JoinableThread::~JoinableThread().
pthread_attr_t ibrcommon::Thread::attr [protected] |
int ibrcommon::Thread::priority [protected] |
size_t ibrcommon::Thread::stack [protected] |
pthread_t ibrcommon::Thread::tid [protected] |
Definition at line 61 of file Thread.h.
Referenced by detach(), ibrcommon::JoinableThread::join(), kill(), and operator==().