IBR-DTNSuite  0.10
ibrcommon::Thread Class Referenceabstract

#include <Thread.h>

Inheritance diagram for ibrcommon::Thread:
Inheritance graph
Collaboration diagram for ibrcommon::Thread:
Collaboration graph

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
 

Detailed Description

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.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 56 of file Thread.h.

Member Enumeration Documentation

Enumerator
THREAD_CREATED 
THREAD_STARTED 
THREAD_INITIALIZED 
THREAD_RUNNING 
THREAD_CANCELLED 
THREAD_FINALIZING 
THREAD_JOINABLE 
THREAD_FINALIZED 

Definition at line 59 of file Thread.h.

Constructor & Destructor Documentation

ibrcommon::Thread::Thread ( size_t  stack = DEFAULT_STACKSIZE)
protected

Create a thread object that will have a preset stack size. If 0 is used, then the stack size is os defined/default.

Parameters
stacksize 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 146 of file Thread.cpp.

References attr.

Member Function Documentation

void * ibrcommon::Thread::__execute__ ( void *  obj) throw ()
staticprotected

static execute thread method

Definition at line 71 of file Thread.cpp.

References _detached, _state, finally(), and run().

Referenced by ibrcommon::JoinableThread::start(), and ibrcommon::DetachedThread::start().

Here is the call graph for this function:

void ibrcommon::Thread::cancel ( ) throw ()
protected
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.

bool ibrcommon::Thread::equal ( pthread_t  thread1,
pthread_t  thread2 
)
staticprotected

Determine if two thread identifiers refer to the same thread.

Parameters
thread1to test.
thread2to test.
Returns
true if both are the same context.

Definition at line 200 of file Thread.cpp.

Referenced by ibrcommon::JoinableThread::join(), and operator==().

virtual void ibrcommon::Thread::finally ( void  ) throw ()
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__().

size_t ibrcommon::Thread::getNumberOfProcessors ( )
static

Definition at line 46 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 205 of file Thread.cpp.

References _state, and THREAD_FINALIZED.

int ibrcommon::Thread::kill ( int  sig)
protected

sends a signal to this thread

Parameters
sig
Returns

Definition at line 165 of file Thread.cpp.

References tid.

bool ibrcommon::Thread::operator== ( const ibrcommon::Thread other)
inline

Determine if two thread identifiers refer to the same thread.

Parameters
otherThe thread to compare.
Returns
True, if both threads are the same.

Definition at line 151 of file Thread.h.

References equal(), and tid.

Here is the call graph for this function:

void ibrcommon::Thread::reset ( ) throw (ThreadException)

Reset this thread to initial state

Definition at line 151 of file Thread.cpp.

References _detached, _state, attr, ibrcommon::ThreadsafeState< T >::reset(), THREAD_CREATED, THREAD_FINALIZED, and tid.

Here is the call graph for this function:

virtual void ibrcommon::Thread::setup ( void  ) throw ()
inlinevirtual

This method is called before the run.

Reimplemented in dtn::net::TCPConnection, dtn::api::ClientHandler, dtn::net::LOWPANConnection, and dtn::net::DatagramConnection.

Definition at line 123 of file Thread.h.

void ibrcommon::Thread::sleep ( time_t  timeout)
static

Sleep current thread for a specified time period.

Parameters
timeoutto sleep for in milliseconds.

Definition at line 129 of file Thread.cpp.

Referenced by dtn::api::ApiServer::componentDown(), dtn::net::WifiP2PManager::componentRun(), dtn::net::FileMonitor::componentRun(), dtn::net::HTTPConvergenceLayer::componentRun(), and dtn::net::WifiP2PManager::connectionEstablished().

Member Data Documentation

bool ibrcommon::Thread::_detached
protected

Definition at line 86 of file Thread.h.

Referenced by __execute__(), and reset().

pthread_attr_t ibrcommon::Thread::attr
protected

Definition at line 83 of file Thread.h.

Referenced by reset(), Thread(), and ~Thread().

int ibrcommon::Thread::priority
protected

Definition at line 80 of file Thread.h.

size_t ibrcommon::Thread::stack
protected

Definition at line 77 of file Thread.h.

pthread_t ibrcommon::Thread::tid
protected

Definition at line 74 of file Thread.h.

Referenced by ibrcommon::JoinableThread::join(), kill(), operator==(), and reset().


The documentation for this class was generated from the following files: