base::Thread Class Reference

Schedules threads and wraps OS thread library. More...

#include <base_thread.hh>

Inheritance diagram for base::Thread:

base::Threadable

List of all members.

Public Types

enum  ePriority { ePriority_DEFAULT, ePriority_LOW, ePriority_HIGH }
typedef void(* ThreadFunc )(long)
 the C function where a new thread begins.
typedef volatile
pthread_t 
AtomicTid

Public Member Functions

Tid Run (const RunArgs &runArgs)
void Yield (void)
void Sleep (Milliseconds millisecs)
bool Wait (Tid tid)
void Wait (Condition &condition)
void Awaken (Condition &condition)
uint Cnt (void)
bool IfMain (void)
Tid GetTid (void)
void * SuballocateThreadMemory (uint bytes)

Private Member Functions

 Thread (void)
 ~Thread ()
void InitPthreadAttr ()
CLASS_METHOD void * Run2 (void *runArgs)
void Run3 (const RunArgs &runArgs)
void NewThreadMemory (const uint threadMemorySize)
void DeleteThreadMemory (void)

Private Attributes

bool mValid
Atomic::Int mThreadCnt
 how many threads are active
Tid mMainTid
 TID of main thread.
vector< pthread_attr_t > mPthreadAttr
 pthread attributes such as priority etc
pthread_key_t mThreadMemoryKey
 key to per-thread memory block on heap
CLASS_VAR uint msDefaultThreadMemorySize = DEFAULT_THREAD_MEMORY_SIZE
 default arg for Run()

Friends

class Global
void * SuballocateThreadMemory (const uint bytes)

Classes

class  Condition
 Wait-on-condition. More...
struct  RunArgs
 Args for Thread::Run(). More...
struct  Tid
 Thread ID (opaque). More...


Detailed Description

Schedules threads and wraps OS thread library.

Ironically, the Thread class itself should be Threadable.


Member Typedef Documentation

typedef void(* base::Thread::ThreadFunc)(long)

the C function where a new thread begins.

typedef volatile pthread_t base::Thread::AtomicTid


Member Enumeration Documentation

enum base::Thread::ePriority

Enumerator:
ePriority_DEFAULT 
ePriority_LOW 
ePriority_HIGH 


Constructor & Destructor Documentation

base::Thread::Thread ( void   )  [private]

ctor.

Precondition:
Must be run by main thread. Instantiate this once.

base::Thread::~Thread (  )  [private]


Member Function Documentation

Thread::Tid base::Thread::Run ( const RunArgs runArgs  ) 

Spawn a thread to execute a C function.

Thread::Run() --> Thread::Run2() --> Thread::Run3() --> target function

NOTE: This must be re-entrant.

void base::Thread::Yield ( void   ) 

Yield CPU.

void base::Thread::Sleep ( Milliseconds  millisecs  ) 

Sleep.

bool base::Thread::Wait ( Tid  tid  ) 

Wait for a thread to finish (join).

Returns:
True if joined ok.

void base::Thread::Wait ( Condition condition  ) 

void base::Thread::Awaken ( Condition condition  ) 

uint base::Thread::Cnt ( void   ) 

Returns:
Number of active threads.

bool base::Thread::IfMain ( void   ) 

Returns:
True if this is the main thread.

Thread::Tid base::Thread::GetTid ( void   ) 

Returns:
ID of this thread.

void* base::Thread::SuballocateThreadMemory ( uint  bytes  ) 

void base::Thread::InitPthreadAttr ( void   )  [private]

For ctor. Pre-initialize POSIX thread attributes. POSIX thread attributes were designed for reuse. pthread_setschedprio() is rarely implemented (Fedora 3 [2004] lacks it).

void * base::Thread::Run2 ( void *  runArgs  )  [private]

void base::Thread::Run3 ( const RunArgs runArgs  )  [private]

void base::Thread::NewThreadMemory ( const uint  threadMemorySize  )  [private]

Allocate heap memory for this thread. Used by PerThreadPtr. Applies to main thread too.

void base::Thread::DeleteThreadMemory ( void   )  [private]


Friends And Related Function Documentation

friend class Global [friend]

void * base::Thread::SuballocateThreadMemory ( const uint  bytes  )  [friend]

Suballocate thread memory.


Member Data Documentation

bool base::Thread::mValid [private]

Atomic::Int base::Thread::mThreadCnt [private]

how many threads are active

Tid base::Thread::mMainTid [private]

TID of main thread.

vector<pthread_attr_t> base::Thread::mPthreadAttr [private]

pthread attributes such as priority etc

pthread_key_t base::Thread::mThreadMemoryKey [private]

key to per-thread memory block on heap

uint base::Thread::msDefaultThreadMemorySize = DEFAULT_THREAD_MEMORY_SIZE [private]

default arg for Run()


The documentation for this class was generated from the following files: Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:19 2007