InspIRCd  3.0
Classes | Public Member Functions | Static Public Member Functions | List of all members
ThreadEngine Class Reference

#include <threadengine_pthread.h>

Classes

struct  ThreadState
 

Public Member Functions

void Start (Thread *thread_to_init)
 
void Stop (Thread *thread)
 
void Start (Thread *thread_to_init)
 
void Stop (Thread *thread)
 

Static Public Member Functions

static DWORD WINAPI Entry (void *parameter)
 

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.

Member Function Documentation

◆ Start() [1/2]

void ThreadEngine::Start ( Thread thread_to_init)

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_initPointer to a newly allocated Thread derived object.

◆ Start() [2/2]

void ThreadEngine::Start ( Thread thread_to_init)

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_initPointer to a newly allocated Thread derived object.

◆ Stop() [1/2]

void ThreadEngine::Stop ( Thread thread)

Stop a thread gracefully. First, this function asks the thread to terminate by calling Thread::SetExitFlag(). Next, it waits until the thread terminates (on the operating system level). Finally, all OS-level resources associated with the thread are released. The Thread instance passed to the function is NOT freed. When this function returns, the thread is stopped and you can destroy it or restart it at a later point. Stopping a thread that is not running is a bug.

Parameters
threadThe thread to stop.

◆ Stop() [2/2]

void ThreadEngine::Stop ( Thread thread)

Stop a thread gracefully. First, this function asks the thread to terminate by calling Thread::SetExitFlag(). Next, it waits until the thread terminates (on the operating system level). Finally, all OS-level resources associated with the thread are released. The Thread instance passed to the function is NOT freed. When this function returns, the thread is stopped and you can destroy it or restart it at a later point. Stopping a thread that is not running is a bug.

Parameters
threadThe thread to stop.

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