amino::Thread Class Reference

#include <thread.h>

Inheritance diagram for amino::Thread:

amino::Runnable test::ConditionThread test::LockThread test::MutexThread test::RecursiveLockThread test::RecursiveMutexThread test::TestThread< ParaType > test::PushThread< DequeType, ParaType, CLASS_NAME > test::TakeThread< DequeType, ParaType, CLASS_NAME > test::Thread4Dir< DequeType, ParaType, CLASS_NAME > test::Thread4Dir< DequeType, ParaType, CLASS_NAME > test::Thread4Dir< DequeType, ParaType, CLASS_NAME > test::ThreadDeleteKey< DictType, ParaType, CLASS_NAME > test::ThreadDeleteValue< DictType, ParaType, CLASS_NAME > test::ThreadDequeue< QueueType, ParaType, CLASS_NAME > test::ThreadDequeue< QueueType, ParaType, CLASS_NAME > test::ThreadEnqueue< QueueType, ParaType, CLASS_NAME > test::ThreadEnqueue< QueueType, ParaType, CLASS_NAME > test::ThreadFindKey< DictType, ParaType, CLASS_NAME > test::ThreadFindValue< DictType, ParaType, CLASS_NAME > test::ThreadInsert< DictType, ParaType, CLASS_NAME > test::ThreadInsert< DictType, ParaType, CLASS_NAME > test::ThreadInsert< DictType, ParaType, CLASS_NAME > test::ThreadInsert< DictType, ParaType, CLASS_NAME > test::ThreadPop< TestType, ParaType, CLASS_NAME > test::ThreadPush< TestType, ParaType, CLASS_NAME > test::ThreadPush_front< ListType, ParaType, CLASS_NAME > test::ThreadPushRight< DequeType, ParaType, CLASS_NAME > test::ThreadPushRight< DequeType, ParaType, CLASS_NAME > test::ThreadRemove< ListType, ParaType, CLASS_NAME > test::ThreadRemove< ListType, ParaType, CLASS_NAME > ThreadMath< ParaType, CLASS_NAME >

List of all members.

Public Types

typedef pthread_t native_handler_type

Public Member Functions

 Thread ()
 Thread (int id)
 Thread (string n, Runnable *r=NULL)
 Thread (Runnable *r)
 Create a new thread from a runnable object.
template<class F>
 Thread (F &f)
 This constructor will create a thread from a function object directly. The new thread will be start imediately. This class is in compatible with the C++ 0X standard.
virtual void * run ()
 default run() method, which is intended to be overrided by subclass.
void setRunner (Runnable *r)
 set internal runner of this thread.
void start ()
 Start to execute this thread.
native_handler_type native_handle ()
 return OS handler of background OS handler
void setName (string name)
string getName ()
void join ()
 caller thread will be blocked until this thread exits.
bool joinable () const
 this method is used to tell if this thread can be joined. TODO: if a thread is not started, it's not joinable. Modify it!
void detach ()
 Detach this thread object with background OS thread.
virtual ~Thread ()

Static Public Member Functions

template<class F>
static void * callFuncObj (void *ob)
 Helper function which calls a function object.

Protected Attributes

int threadId
pthread_t tid
string name


Detailed Description

@ This class is used to wrap OS thread, which allows application logic executes in parallel. Now it supports two kinds of initilization arguments:

  1. Function object
  2. Runnable object

We should use Function object in all of the library code unless executor framework is used. Runnable object is only for using with executor framework.


Member Typedef Documentation


Constructor & Destructor Documentation

amino::Thread::Thread (  )  [inline]

amino::Thread::Thread ( int  id  )  [inline]

amino::Thread::Thread ( string  n,
Runnable r = NULL 
) [inline]

Create a new thread with a runnable object.

Deprecated:

amino::Thread::Thread ( Runnable r  )  [inline]

Create a new thread from a runnable object.

Warning:
This constructor should not be used unless using executor framework

template<class F>
amino::Thread::Thread ( F &  f  )  [inline, explicit]

This constructor will create a thread from a function object directly. The new thread will be start imediately. This class is in compatible with the C++ 0X standard.

Parameters:
f A function object which will be executed in another thread.

virtual amino::Thread::~Thread (  )  [inline, virtual]


Member Function Documentation

template<class F>
static void* amino::Thread::callFuncObj ( void *  ob  )  [inline, static]

Helper function which calls a function object.

This function exists for calling function object from a pthread call

virtual void* amino::Thread::run (  )  [inline, virtual]

default run() method, which is intended to be overrided by subclass.

Implements amino::Runnable.

Reimplemented in test::ConditionThread, test::LockThread, test::RecursiveLockThread, test::MutexThread, test::RecursiveMutexThread, ThreadMath< ParaType, CLASS_NAME >, test::Thread4Dir< DequeType, ParaType, CLASS_NAME >, test::ThreadPushRight< DequeType, ParaType, CLASS_NAME >, test::TakeThread< DequeType, ParaType, CLASS_NAME >, test::PushThread< DequeType, ParaType, CLASS_NAME >, test::Thread4Dir< DequeType, ParaType, CLASS_NAME >, test::Thread4Dir< DequeType, ParaType, CLASS_NAME >, test::ThreadPushRight< DequeType, ParaType, CLASS_NAME >, test::ThreadInsert< DictType, ParaType, CLASS_NAME >, test::ThreadDeleteKey< DictType, ParaType, CLASS_NAME >, test::ThreadDeleteValue< DictType, ParaType, CLASS_NAME >, test::ThreadFindValue< DictType, ParaType, CLASS_NAME >, test::ThreadFindKey< DictType, ParaType, CLASS_NAME >, test::ThreadInsert< DictType, ParaType, CLASS_NAME >, test::ThreadInsert< DictType, ParaType, CLASS_NAME >, test::ThreadPush_front< ListType, ParaType, CLASS_NAME >, test::ThreadRemove< ListType, ParaType, CLASS_NAME >, test::ThreadEnqueue< QueueType, ParaType, CLASS_NAME >, test::ThreadDequeue< QueueType, ParaType, CLASS_NAME >, test::ThreadEnqueue< QueueType, ParaType, CLASS_NAME >, test::ThreadDequeue< QueueType, ParaType, CLASS_NAME >, test::ThreadInsert< DictType, ParaType, CLASS_NAME >, test::ThreadRemove< ListType, ParaType, CLASS_NAME >, test::ThreadPush< TestType, ParaType, CLASS_NAME >, and test::ThreadPop< TestType, ParaType, CLASS_NAME >.

void amino::Thread::setRunner ( Runnable r  )  [inline]

set internal runner of this thread.

Where runner is set, the thread will execute runner->run() instead of its own run() method.

void amino::Thread::start (  )  [inline]

Start to execute this thread.

If the runner is set, it will be executed. If not, the thread.run() method will be executed.

native_handler_type amino::Thread::native_handle (  )  [inline]

return OS handler of background OS handler

void amino::Thread::setName ( string  name  )  [inline]

string amino::Thread::getName (  )  [inline]

void amino::Thread::join (  )  [inline]

caller thread will be blocked until this thread exits.

bool amino::Thread::joinable (  )  const [inline]

this method is used to tell if this thread can be joined. TODO: if a thread is not started, it's not joinable. Modify it!

void amino::Thread::detach (  )  [inline]

Detach this thread object with background OS thread.


Member Data Documentation

int amino::Thread::threadId [protected]

pthread_t amino::Thread::tid [protected]

string amino::Thread::name [protected]


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

Generated on Tue Dec 9 13:39:40 2008 for Amino by  doxygen 1.5.6