Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ThreadKernel Class Reference

Thread manager which keeps track of the running threads. More...

#include <thread.h>

Collaboration diagram for ThreadKernel:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ~ThreadKernel ()

Static Public Member Functions

void init ()
 Initialize the thread kernel.

void cleanup ()
 Cleanup thread kernel.

int NRunningThreads ()
 Ask the kernel about the number of threads currently running.


Private Member Functions

void _PhookNotifier (gpointer ptr)
void * _ThreadFuncWrapper (void *ptr)
void _unregister (ExecutionThread *et)
int _NRunningThreads ()
 ThreadKernel (const ThreadKernel &)
 Never call these:.

void operator= (const ThreadKernel &)
 ThreadKernel ()

Static Private Member Functions

void unregister (ExecutionThread *et)
void PhookNotifier (gpointer ptr)
void * ThreadFuncWrapper (void *ptr)

Private Attributes

GPrivate * phook
 This is used to get informed about thread exits.

RecursiveMutex mutex
 Protect internal data structures.

LinkedList< TNodethreadlist
 The thread kernel holds a list of all running threads.

int nrunning
 Count number of elements in the list:.


Static Private Attributes

ThreadKernelkernel = NULL
 There exists exactly one instance of the thread kernel.


Friends

class ExecutionThread

Detailed Description

Thread manager which keeps track of the running threads.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
Never create an object of type ThreadKernel; always use the static members.

Note:
Before using any threads, initialize the thread kernel using ThreadKernel::init() (static member). This should be called from the main execution thread. You can clean it up using ThreadKernel::cleanup() when done.

Definition at line 49 of file thread.h.


Constructor & Destructor Documentation

ThreadKernel::ThreadKernel const ThreadKernel  )  [private]
 

Never call these:.

ThreadKernel::ThreadKernel  )  [private]
 

NEver create an object of type ThreadKernel. Only use the static members.

Definition at line 162 of file thread.cc.

References Assert, CritAssert, kernel, RecursiveMutex::lock(), mutex, phook, PhookNotifier(), and RecursiveMutex::unlock().

Referenced by init().

ThreadKernel::~ThreadKernel  ) 
 

Definition at line 188 of file thread.cc.

References Assert, CritAssert, LinkedList< TNode >::IsEmpty(), kernel, RecursiveMutex::lock(), mutex, nrunning, phook, LinkedList< TNode >::PopFirst(), threadlist, and RecursiveMutex::unlock().


Member Function Documentation

int ThreadKernel::_NRunningThreads  )  [private]
 

Definition at line 24 of file thread.cc.

References RecursiveMutex::lock(), mutex, nrunning, and RecursiveMutex::unlock().

Referenced by NRunningThreads().

void ThreadKernel::_PhookNotifier gpointer  ptr  )  [private]
 

Definition at line 73 of file thread.cc.

References CritAssert, LinkedList< TNode >::dequeue(), ThreadKernel::TNode::execthread, ExecutionThread::handle, RecursiveMutex::lock(), mutex, nrunning, ThreadKernel::TNode::thread, threadlist, and RecursiveMutex::unlock().

Referenced by PhookNotifier().

void * ThreadKernel::_ThreadFuncWrapper void *  ptr  )  [private]
 

Definition at line 34 of file thread.cc.

References LinkedList< TNode >::append(), CritAssert, ThreadKernel::TNode::execthread, ExecutionThread::handle, RecursiveMutex::lock(), mutex, nrunning, phook, ExecutionThread::run(), ThreadKernel::TNode::thread, threadlist, and RecursiveMutex::unlock().

Referenced by ThreadFuncWrapper().

void ThreadKernel::_unregister ExecutionThread et  )  [private]
 

For internal use only.

From static functions, "forwarded":

Definition at line 126 of file thread.cc.

References ThreadKernel::TNode::execthread, ExecutionThread::handle, kernel, RecursiveMutex::lock(), mutex, and RecursiveMutex::unlock().

Referenced by unregister().

void ThreadKernel::cleanup  )  [static]
 

Cleanup thread kernel.

This can be used to clean up the thread kernel before exiting in order to get allocation debugging happy :)

Attention:
Be sure to only call this function if no threads (other than the main thread) are running any more.

Definition at line 155 of file thread.cc.

References kernel.

void ThreadKernel::init  )  [static]
 

Initialize the thread kernel.

This must be done before starting any threads.

Definition at line 149 of file thread.cc.

References ThreadKernel().

int ThreadKernel::NRunningThreads  )  [inline, static]
 

Ask the kernel about the number of threads currently running.

Returns:
The number of running threads or -1 in case the thread kernel was not initialized. The main thread does not count as running thread. This means you may safely cleanup the thread kernel in case this returns 0.

Definition at line 130 of file thread.h.

References _NRunningThreads(), and kernel.

void ThreadKernel::operator= const ThreadKernel  )  [private]
 

void ThreadKernel::PhookNotifier gpointer  ptr  )  [static, private]
 

For internal use only.

Used as callback by phook.

Definition at line 119 of file thread.cc.

References _PhookNotifier(), and kernel.

Referenced by ThreadKernel().

void * ThreadKernel::ThreadFuncWrapper void *  ptr  )  [static, private]
 

For internal use only.

Used as wrapper to start threads.

Definition at line 66 of file thread.cc.

References _ThreadFuncWrapper(), and kernel.

void ThreadKernel::unregister ExecutionThread et  )  [inline, static, private]
 

Internally used by ExecutionThread to unregister when destroyed although there is still a handle attached.

Definition at line 69 of file thread.h.

References _unregister(), and kernel.

Referenced by ExecutionThread::~ExecutionThread().


Friends And Related Function Documentation

friend class ExecutionThread [friend]
 

Definition at line 51 of file thread.h.


Member Data Documentation

ThreadKernel * ThreadKernel::kernel = NULL [static, private]
 

There exists exactly one instance of the thread kernel.

Definition at line 21 of file thread.cc.

Referenced by _unregister(), cleanup(), NRunningThreads(), PhookNotifier(), ThreadFuncWrapper(), ThreadKernel(), unregister(), and ~ThreadKernel().

RecursiveMutex ThreadKernel::mutex [private]
 

Protect internal data structures.

Definition at line 76 of file thread.h.

Referenced by _NRunningThreads(), _PhookNotifier(), _ThreadFuncWrapper(), _unregister(), ThreadKernel(), and ~ThreadKernel().

int ThreadKernel::nrunning [private]
 

Count number of elements in the list:.

Definition at line 81 of file thread.h.

Referenced by _NRunningThreads(), _PhookNotifier(), _ThreadFuncWrapper(), and ~ThreadKernel().

GPrivate* ThreadKernel::phook [private]
 

This is used to get informed about thread exits.

Definition at line 73 of file thread.h.

Referenced by _ThreadFuncWrapper(), ThreadKernel(), and ~ThreadKernel().

LinkedList<TNode> ThreadKernel::threadlist [private]
 

The thread kernel holds a list of all running threads.

Definition at line 79 of file thread.h.

Referenced by _PhookNotifier(), _ThreadFuncWrapper(), and ~ThreadKernel().


The documentation for this class was generated from the following files:
Generated on Sat Feb 19 22:35:44 2005 for Ray by doxygen 1.3.5