Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

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

Platform independent class for handling execution threads. More...

#include <thread.h>

Inheritance diagram for cmn_Thread:
Inheritance graph
[legend]

List of all members.

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

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 200 of file thread.h.


Member Enumeration Documentation

Enumerator:
PRIO_LOW 
PRIO_NORM 
PRIO_HIGH 

Definition at line 203 of file thread.h.

                      {
        PRIO_LOW    = omni_thread::PRIORITY_LOW,
        PRIO_NORM   = omni_thread::PRIORITY_NORMAL,
        PRIO_HIGH   = omni_thread::PRIORITY_HIGH
    };

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 209 of file thread.h.

                   {
        ST_NEW          = omni_thread::STATE_NEW,
        ST_RUNNING      = omni_thread::STATE_RUNNING,
        ST_TERM         = omni_thread::STATE_TERMINATED
    };


Constructor & Destructor Documentation

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

Definition at line 226 of file thread.h.

Referenced by Create().

    : 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 232 of file thread.h.

    : 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 256 of file thread.h.

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


Member Function Documentation

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

Definition at line 354 of file cmn_thread.cpp.

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

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

                                                                             {
    log_FUNC_A_m(Create,
        "<detached>" <<
        "fn: " << fn <<
        "arg: " << arg
    );

    cmn_Thread* t = new cmn_Thread(fn, arg, pri);
    t->Start();
    return t;
}

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 366 of file cmn_thread.cpp.

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

                                                                              {
    log_FUNC_A_m(Create,
        "<undetached>" <<
        "fn: " << fn <<
        "arg: " << arg
    );

    cmn_Thread* t = new cmn_Thread(fn, arg, pri);
    t->Start();
    return t;
}

Here is the call graph for this function:

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

Definition at line 339 of file cmn_thread.cpp.

References log_FUNC_m, and OMNITHREAD_EXEC_m.

                                        {
    log_FUNC_m(Exit);

    OMNITHREAD_EXEC_m(Exit, exit(return_value));
}

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

Definition at line 319 of file thread.h.

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

                                                           {
        unsigned long absSec, absNSec;
        omni_thread::get_time(&absSec, &absNSec, rel_sec, 0);
        return absSec;
    }

Here is the caller graph for this function:

int cmn_Thread::Id (  )  [inline]

Definition at line 363 of file thread.h.

References id.

             { 
        return id(); 
    }

void cmn_Thread::Join ( void **  arg  ) 

Definition at line 333 of file cmn_thread.cpp.

References log_FUNC_m, and OMNITHREAD_EXEC_m.

Referenced by ipc_Corba::Destroy(), and ClientConf_t::~ClientConf_t().

                                {
    log_FUNC_m(Join);

    OMNITHREAD_EXEC_m(Join, join(arg));
}

Here is the caller graph for this function:

ThPriority_e cmn_Thread::Priority (  )  [inline]

Definition at line 355 of file thread.h.

                            {
        return (ThPriority_e)priority();
    }

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

Reimplemented in hsm_HL7MessageProxy, and ipc_Shutdown.

Definition at line 348 of file thread.h.

{ return NULL; }

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

Definition at line 306 of file thread.h.

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

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

Definition at line 283 of file thread.h.

                                          {
        set_priority((priority_t)a_prio);
    };

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

Definition at line 349 of file cmn_thread.cpp.

References OMNITHREAD_EXEC_m.

                                                                 {
    OMNITHREAD_EXEC_m(Sleep, sleep(secs, nanosecs));
}

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

Definition at line 333 of file thread.h.

                                     {
        return stacksize();
    }

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

Definition at line 329 of file thread.h.

                                            {
        stacksize(sz);
    };

void cmn_Thread::Start (  ) 
void cmn_Thread::StartUndetached (  ) 

Definition at line 326 of file cmn_thread.cpp.

References log_FUNC_m, and OMNITHREAD_EXEC_m.

Referenced by ipc_Corba::Init(), and ClientConf_t::Init().

                                 {
    log_FUNC_m(StartUndetached);

    // Run omni_thread's function
    OMNITHREAD_EXEC_m(StartUndetached, start_undetached());
}

Here is the caller graph for this function:

ThState_e cmn_Thread::State (  )  [inline]

Definition at line 359 of file thread.h.

                      {
        return (ThState_e)state();
    }

void cmn_Thread::YieldThread (  )  [static]

Definition at line 345 of file cmn_thread.cpp.

References OMNITHREAD_EXEC_m.


Member Data Documentation


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