The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

ThreadEngine Class Reference

The ThreadEngine class has the responsibility of initialising Thread derived classes. More...

#include <threadengine.h>

Inheritance diagram for ThreadEngine:

Inheritance graph
[legend]
Collaboration diagram for ThreadEngine:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ThreadEngine (InspIRCd *Instance)
 Constructor.
virtual ~ThreadEngine ()
 Destructor.
void Lock ()
 Lock the system wide mutex.
void Unlock ()
 Unlock the system wide mutex.
virtual void Run ()=0
 Run the newly created thread.
virtual void Create (Thread *thread_to_init)=0
 Create a new thread.
virtual void FreeThread (Thread *thread)=0
 This is called by the default destructor of the Thread class to ensure that the thread engine which created the thread is responsible for destroying it.
virtual const std::string GetName ()
 Returns the thread engine's name for display purposes.

Protected Member Functions

virtual bool Mutex (bool enable)=0
 Enable or disable system-wide mutex for threading.

Protected Attributes

InspIRCdServerInstance
 Creator instance.
ThreadNewThread
 New Thread being created.

Detailed Description

The ThreadEngine class has the responsibility of initialising Thread derived classes.

It does this by creating operating system level threads which are then associated with the class transparently. This allows Thread classes to be derived without needing to know how the OS implements threads. You should ensure that any sections of code that use threads are threadsafe and do not interact with any other parts of the code which are NOT known threadsafe! If you really MUST access non-threadsafe code from a Thread, use the Mutex class to wrap access to the code carefully.

Definition at line 36 of file threadengine.h.


Constructor & Destructor Documentation

ThreadEngine::ThreadEngine InspIRCd Instance  ) 
 

Constructor.

Parameters:
Instance Creator object

Definition at line 23 of file threadengine.cpp.

ThreadEngine::~ThreadEngine  )  [virtual]
 

Destructor.

Definition at line 27 of file threadengine.cpp.


Member Function Documentation

virtual void ThreadEngine::Create Thread thread_to_init  )  [pure virtual]
 

Create a new thread.

This takes an already allocated Thread* pointer and initializes it to use this threading engine. On failure, this function may throw a CoreException.

Parameters:
thread_to_init Pointer to a newly allocated Thread derived object.

Referenced by TestSuite::DoThreadTests(), InspIRCd::InspIRCd(), ModuleMsSQL::ModuleMsSQL(), and ModuleSQL::ModuleSQL().

virtual void ThreadEngine::FreeThread Thread thread  )  [pure virtual]
 

This is called by the default destructor of the Thread class to ensure that the thread engine which created the thread is responsible for destroying it.

Parameters:
thread Existing and active thread to delete.

virtual const std::string ThreadEngine::GetName  )  [inline, virtual]
 

Returns the thread engine's name for display purposes.

Returns:
The thread engine name

Definition at line 101 of file threadengine.h.

Referenced by TestSuite::DoThreadTests().

void ThreadEngine::Lock  )  [inline]
 

Lock the system wide mutex.

See the documentation for ThreadEngine::Mutex().

Definition at line 72 of file threadengine.h.

Referenced by ServerConfig::Read(), and ConfigReaderThread::Run().

virtual bool ThreadEngine::Mutex bool  enable  )  [protected, pure virtual]
 

Enable or disable system-wide mutex for threading.

Remember that if you toggle the mutex you MUST UNSET IT LATER otherwise the program will DEADLOCK! It is recommended that you AVOID USE OF THIS METHOD and use your own Mutex class, this function is mainly reserved for use by the core and by the Thread engine itself.

Parameters:
enable True to lock the mutex.

virtual void ThreadEngine::Run  )  [pure virtual]
 

Run the newly created thread.

void ThreadEngine::Unlock  )  [inline]
 

Unlock the system wide mutex.

See the documentation for ThreadEngine::Mutex()

Definition at line 77 of file threadengine.h.

Referenced by ServerConfig::Read(), and ConfigReaderThread::Run().


Member Data Documentation

Thread* ThreadEngine::NewThread [protected]
 

New Thread being created.

Definition at line 46 of file threadengine.h.

InspIRCd* ThreadEngine::ServerInstance [protected]
 

Creator instance.

Definition at line 42 of file threadengine.h.


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