cmn_Thread Class Reference
[Common, basic classes, functions and types]

#include <thread.h>

Inheritance diagram for cmn_Thread:

Inheritance graph
[legend]

List of all members.


Detailed Description

Platform independent class for handling execution threads.

cmn_Thread is currently based on AT&T's omni_thread, which is a part of CORBA ORB omniORB.

Basic concepts

There are two ways of defining which function will be executed in a thread:

  1. Use cmn_Thread and pass a pointer to a (non member!) function and (and optional function argument and priority) as an argument. Passed function will be executed in new thread. Thread starts running when Start() or StartUndetached() function is called.
  2. Implement new class, which is derived from cmn_Thread and implement virtual Run() and RunUndetached() functions and customized constructor. Thread execution is triggered by using Start() or StartUndetached().

Threads can run in either detached or undetached mode:

The preferred mode to use is detached mode. If the thread performs data processing that must be returned to the creator thread then there are other means of passing the value back.

For instance: the argument that is passed to the thread can be used to store the results and a condition (cmn_Condition::Wait() and cmn_Condition::Signal()) can be used to inform the creator that the thread has finished.

How to use cmn_Thread?

Definition at line 186 of file thread.h.


Public Types

enum  ThPriority_e {
  PRIO_LOW = omni_thread::PRIORITY_LOW, PRIO_NORM = omni_thread::PRIORITY_NORMAL,
  PRIO_HIGH = omni_thread::PRIORITY_HIGH
}
enum  ThState_e {
  ST_NEW = omni_thread::STATE_NEW, ST_RUNNING = omni_thread::STATE_RUNNING,
  ST_TERM = omni_thread::STATE_TERMINATED
}

Public Member Functions

 cmn_Thread (void(*fn)(void *), void *arg=NULL, ThPriority_e a_pri=PRIO_NORM)
 cmn_Thread (void *(*fn)(void *), void *arg=NULL, ThPriority_e a_pri=PRIO_NORM)
void Start ()
void StartUndetached ()
void Join (void **arg)
void SetPriority (ThPriority_e a_prio)
ThPriority_e Priority ()
ThState_e State ()
int Id ()

Static Public Member Functions

static cmn_ThreadCreate (void(*fn)(void *), void *arg=NULL, ThPriority_e pri=PRIO_NORM)
static cmn_ThreadCreate (void *(*fn)(void *), void *arg=NULL, ThPriority_e pri=PRIO_NORM)
static void Exit (void *return_value=NULL)
static cmn_ThreadSelf ()
static void YieldThread ()
static void Sleep (unsigned long secs, unsigned long nanosecs=0)
static ivd_Time32_t GetTime (unsigned long rel_sec=0)
static void StackSize (unsigned long sz)
static unsigned long StackSize ()

Protected Member Functions

 cmn_Thread (void *arg=NULL, ThPriority_e a_pri=PRIO_NORM)

Private Member Functions

virtual void Run (void *arg)
virtual void * RunUndetached (void *arg)

Private Attributes

 log_CLASSID_m

Member Enumeration Documentation

Enumerator:
PRIO_LOW 
PRIO_NORM 
PRIO_HIGH 

Definition at line 189 of file thread.h.

00189                       {
00190         PRIO_LOW    = omni_thread::PRIORITY_LOW,
00191         PRIO_NORM   = omni_thread::PRIORITY_NORMAL,
00192         PRIO_HIGH   = omni_thread::PRIORITY_HIGH
00193     };

Enumerator:
ST_NEW  Thread object exists but thread hasn't started yet.
ST_RUNNING  Thread is running.
ST_TERM  Thread has terminated but storage has not been reclaimed (i.e.

waiting to be joined)

Definition at line 195 of file thread.h.

00195                    {
00197         ST_NEW          = omni_thread::STATE_NEW,
00199         ST_RUNNING      = omni_thread::STATE_RUNNING,
00203         ST_TERM         = omni_thread::STATE_TERMINATED
00204     };


Constructor & Destructor Documentation

cmn_Thread::cmn_Thread ( void(*)(void *)  fn,
void *  arg = NULL,
ThPriority_e  a_pri = PRIO_NORM 
) [inline]

Definition at line 212 of file thread.h.

Referenced by Create().

00216     : omni_thread(fn, arg, (priority_t)a_pri) {};

Here is the caller graph for this function:

cmn_Thread::cmn_Thread ( void *(*)(void *)  fn,
void *  arg = NULL,
ThPriority_e  a_pri = PRIO_NORM 
) [inline]

Definition at line 218 of file thread.h.

00222     : omni_thread(fn, arg, (priority_t)a_pri) {};

cmn_Thread::cmn_Thread ( void *  arg = NULL,
ThPriority_e  a_pri = PRIO_NORM 
) [inline, protected]

Definition at line 242 of file thread.h.

00245     : omni_thread(arg, (priority_t)a_pri) {
00246         // Empty
00247     };


Member Function Documentation

void cmn_Thread::Start (  ) 

void cmn_Thread::StartUndetached (  ) 

Definition at line 312 of file cmn_thread.cpp.

References log_FUNC_m, and OMNITHREAD_EXEC_m.

Referenced by ipc_Corba::Init().

00312                                  {
00313     log_FUNC_m(StartUndetached);
00314 
00315     // Run omni_thread's function
00316     OMNITHREAD_EXEC_m(StartUndetached, start_undetached());
00317 }

Here is the caller graph for this function:

void cmn_Thread::Join ( void **  arg  ) 

Definition at line 319 of file cmn_thread.cpp.

References log_FUNC_m, and OMNITHREAD_EXEC_m.

Referenced by ipc_Corba::Destroy().

00319                                 {
00320     log_FUNC_m(Join);
00321 
00322     OMNITHREAD_EXEC_m(Join, join(arg));
00323 }

Here is the caller graph for this function:

void cmn_Thread::SetPriority ( ThPriority_e  a_prio  )  [inline]

Definition at line 269 of file thread.h.

00269                                           {
00270         set_priority((priority_t)a_prio);
00271     };

cmn_Thread * cmn_Thread::Create ( void(*)(void *)  fn,
void *  arg = NULL,
ThPriority_e  pri = PRIO_NORM 
) [static]

Definition at line 340 of file cmn_thread.cpp.

References cmn_Thread(), log_FUNC_A_m, and Start().

Referenced by Create(), and i_Job_i::WaitBeasToFinish().

00340                                                                              {
00341     log_FUNC_A_m(Create,
00342         "<detached>" <<
00343         "fn: " << fn <<
00344         "arg: " << arg
00345     );
00346 
00347     cmn_Thread* t = new cmn_Thread(fn, arg, pri);
00348     t->Start();
00349     return t;
00350 }

Here is the call graph for this function:

Here is the caller graph for this function:

cmn_Thread * cmn_Thread::Create ( void *(*)(void *)  fn,
void *  arg = NULL,
ThPriority_e  pri = PRIO_NORM 
) [static]

Definition at line 352 of file cmn_thread.cpp.

References cmn_Thread(), Create(), log_FUNC_A_m, and Start().

00352                                                                               {
00353     log_FUNC_A_m(Create,
00354         "<undetached>" <<
00355         "fn: " << fn <<
00356         "arg: " << arg
00357     );
00358 
00359     cmn_Thread* t = new cmn_Thread(fn, arg, pri);
00360     t->Start();
00361     return t;
00362 }

Here is the call graph for this function:

void cmn_Thread::Exit ( void *  return_value = NULL  )  [static]

Definition at line 325 of file cmn_thread.cpp.

References log_FUNC_m, and OMNITHREAD_EXEC_m.

00325                                         {
00326     log_FUNC_m(Exit);
00327 
00328     OMNITHREAD_EXEC_m(Exit, exit(return_value));
00329 }

static cmn_Thread* cmn_Thread::Self (  )  [inline, static]

Definition at line 292 of file thread.h.

00292                               {
00293         return dynamic_cast<cmn_Thread*>( self() );
00294     };

void cmn_Thread::YieldThread (  )  [static]

Definition at line 331 of file cmn_thread.cpp.

References OMNITHREAD_EXEC_m.

00331                              {
00332     OMNITHREAD_EXEC_m(YieldThread, yield());
00333 }

void cmn_Thread::Sleep ( unsigned long  secs,
unsigned long  nanosecs = 0 
) [static]

Definition at line 335 of file cmn_thread.cpp.

References OMNITHREAD_EXEC_m.

00335                                                                  {
00336     OMNITHREAD_EXEC_m(Sleep, sleep(secs, nanosecs));
00337 }

static ivd_Time32_t cmn_Thread::GetTime ( unsigned long  rel_sec = 0  )  [inline, static]

Definition at line 305 of file thread.h.

Referenced by df_BlockManager::GetFree(), df_BlockManager::GetFull(), cmn_ThreadCounter::WaitAllEnd(), i_Job_i::WaitBea(), i_Job_i::WaitBeasToFinish(), df_BlockManager::WaitReadersToComplete(), and df_BlockManager::WaitWriterToComplete().

00305                                                            {
00306         unsigned long absSec, absNSec;
00307         omni_thread::get_time(&absSec, &absNSec, rel_sec, 0);
00308         return absSec;
00309     }

Here is the caller graph for this function:

static void cmn_Thread::StackSize ( unsigned long  sz  )  [inline, static]

Definition at line 315 of file thread.h.

00315                                             {
00316         stacksize(sz);
00317     };

static unsigned long cmn_Thread::StackSize (  )  [inline, static]

Definition at line 319 of file thread.h.

00319                                      {
00320         return stacksize();
00321     }

virtual void cmn_Thread::Run ( void *  arg  )  [inline, private, virtual]

virtual void* cmn_Thread::RunUndetached ( void *  arg  )  [inline, private, virtual]

Reimplemented in ipc_Shutdown.

Definition at line 334 of file thread.h.

References NULL.

00334 { return NULL; }

ThPriority_e cmn_Thread::Priority (  )  [inline]

Definition at line 341 of file thread.h.

00341                             {
00342         return (ThPriority_e)priority();
00343     }

ThState_e cmn_Thread::State (  )  [inline]

Definition at line 345 of file thread.h.

00345                       {
00346         return (ThState_e)state();
00347     }

int cmn_Thread::Id (  )  [inline]

Definition at line 349 of file thread.h.

References id.

00349              { 
00350         return id(); 
00351     }


Member Data Documentation


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

Generated on Mon Feb 27 19:05:38 2012 for OPENARCHIVE by  doxygen 1.5.6