#include "Platform.h"
#include <windows.h>
Namespaces | |
namespace | Threading |
Classes | |
struct | Threading::GaThreadParameter |
GaThreadParameter structure contains information needed to start new thread. It has pointer to function which is entry point of thread and pointer to parameters which will be passed to the function. Restrictions of entry point's function of a thread are described by GaThreadFunctionPointer type. More... | |
class | Threading::GaCriticalSection |
GaCriticalSection class is wrapper class for system synchronization object. More... | |
class | Threading::GaSectionLock |
GaSectionLock class is used for automatic access control with help of GaCriticalSection class. Synchronization object can be automatically acquired when instance of GaSectionLock is created. If synchronization object is locked by instance of GaSectionLock it is released when the instance goes out of scope. This mechanism provides simple way of managing critical sections because users don't have to worry about releasing of synchronization object in most cases, but for more complicated cases LOCK and UNLOCK macros can be used with instances of this class or with GaCriticalSection class. GaSectionLock is mainly employed by LOCK_OBJECT and LOCK_THIS_OBJECT . More... | |
class | Threading::GaThread |
GaThread class controls system threads. It wraps system specific control of threading. This class has built-in synchronizator so it is allowed to use LOCK_OBJECT and LOCK_THIS_OBJECT macros with instances of this class. More... | |
Defines | |
#define | ATOMIC_INC(VALUE) _SYSTEM_OR_COMPILER_SPECIFIC_ |
ATOMIC_INC macro atomically increments VALUE by one and returns new value. | |
#define | ATOMIC_DEC(VALUE) _SYSTEM_OR_COMPILER_SPECIFIC_ |
ATOMIC_DEC macro atomically decrements VALUE by one and returns new value. | |
#define | SPINLOCK(LOCK) _SYSTEM_OR_COMPILER_SPECIFIC_ |
SPINLOCK macro defines mechanism of spinlock. | |
#define | ATOMIC_INC(VALUE) InterlockedIncrement( (LONG*)&VALUE ) |
ATOMIC_INC macro atomically increments VALUE by one and returns new value. | |
#define | ATOMIC_DEC(VALUE) InterlockedDecrement( (LONG*)&VALUE ) |
ATOMIC_DEC macro atomically decrements VALUE by one and returns new value. | |
#define | SPINLOCK(LOCK) while( InterlockedExchange( (LONG*)&LOCK, 1 ) ) |
SPINLOCK macro defines mechanism of spinlock. | |
#define | DEFINE_SYNC_CLASS |
DEFINE_SYNC_CLASS macro inserts members to class which are needed to synchronize access to an object. Synchronization is don by using LOCK_OBJECT and LOCK_THIS_OBJECT macros. | |
#define | LOCK(LOCK_NAME) ( LOCK_NAME ).Lock() |
Macro is used to acquire access to critical section protected by synchronization object (GaSectionLock and GaCriticalSection). | |
#define | UNLOCK(LOCK_NAME) ( LOCK_NAME ).Unlock() |
Macro is used when thread exits critical section and releases access to synchronization object (GaSectionLock and GaCriticalSection). | |
#define | LOCK_OBJECT(LOCK_NAME, OBJECT) Threading::GaSectionLock LOCK_NAME( ( OBJECT )->GetSynchronizator(), true ) |
Macro acquires access to an object with built-in synchronizator and prevents concurrent access. It instantiate GaSectionLock object with name lock and acquire access to the object, when execution leave the scope in which LOCK_OBJECT is specified, GaSectionLock object is destroyed and access to the locked object is released. Unlocking access to the object before leaving scope can be done by calling UNLOCK(lock_name) macro. | |
#define | LOCK_THIS_OBJECT(LOCK_NAME) Threading::GaSectionLock LOCK_NAME( &this->_synchronizator, true ) |
Macro acquires access to this and prevents concurrent access. It declares and instantiates GaSectionLock object with name lock and acquire access to this object, when execution leave the scope in which LOCK_OBJECT is specified, GaSectionLock object is destroyed and access to this object is released. Unlocking access to this before leaving scope can be done by calling UNLOCK(lock_name) macro. | |
Typedefs | |
typedef _SYSTEM_OR_COMPILER_SPECIFIC_ | Threading::SystemThread |
This type defines system specific type for storing threads objects or handles to them. | |
typedef _SYSTEM_OR_COMPILER_SPECIFIC_ | Threading::SysSyncObject |
This type defines system specific type for storing synchronization objects or handles to them. System specific synchronization is wrapped by GaCriticalSection class. | |
typedef _SYSTEM_OR_COMPILER_SPECIFIC_ | Threading::SysSemaphoreObject |
This type defines system specific type for storing semaphores objects or handles to them. Manipulation over semaphores is done by MAKE_SEMAPHORE , FREE_SEMAPHORE , LOCK_SEMAPHORE and UNLOCK_SEMAPHORE macros. | |
typedef _SYSTEM_OR_COMPILER_SPECIFIC_ | Threading::SysEventObject |
This type defines system specific type for storing events objects or handles to them. Manipulation over events is done by MAKE_EVENT , FREE_EVENT , WAIT_FOR_EVENT and SIGNAL_EVENT macros. | |
typedef _SYSTEM_OR_COMPILER_SPECIFIC_ | Threading::ThreadFunctionReturn |
This type is used as return value type for functions which are used as threads' entry points. This type hides system specific types which are used for the purpose. | |
typedef _SYSTEM_OR_COMPILER_SPECIFIC_ | Threading::ThreadID |
Variables/objects of this type are used for storing threads' IDs. This type hides system specific types which are used for the purpose. | |
Enumerations | |
enum | Threading::GaThreadStatus { Threading::GATS_RUNNING = 0x1, Threading::GATS_STOPPED = 0x2, Threading::GATS_PAUSED = 0x4, Threading::GATS_NOT_RUNNING = GATS_STOPPED | GATS_PAUSED } |
This enumeration defines possible states of threads. More... | |
Functions | |
bool | Threading::MakeSemaphore (SysSemaphoreObject &semaphoreHandle, int maxCount, int initialCount) |
This function is used to create operating system object for semaphore and to initialize it. | |
bool | Threading::DeleteSemaphore (SysSemaphoreObject &semaphoreHandle) |
This function is used to free operating system semaphore. | |
bool | Threading::LockSemaphore (SysSemaphoreObject &semaphoreHandle) |
This function is used to acquire access to critical section protected by semaphore. | |
bool | Threading::UnlockSemaphore (SysSemaphoreObject &semaphoreHandle, int count) |
This function is used to release access to critical section protected by semaphore. | |
bool | Threading::MakeEvent (SysEventObject &eventHandle, bool intialState) |
This function is used to create operating system object for event and to initialize it. | |
bool | Threading::DeleteEvent (SysEventObject &eventHandle) |
This function is used to free operating system semaphore. | |
bool | Threading::WaitForEvent (SysEventObject &eventHandle) |
This function is used to block calling thread until event reaches signaled state. When calling thread is released, event is restared to non-signaled state. | |
bool | Threading::SignalEvent (SysEventObject &eventHandle) |
This function is used to set event to signaled state. | |
typedef | Threading::ThreadFunctionReturn (GACALL *ThreadFunctionPointer)(GaThread * |
ThreadFunctionPointer is pointer to function used as thread's entry point. Entry point function must obey restriction of this type: 1. Function must return value of ThreadFunctionReturn type. 2. Function must use GACALL calling convention. 3. Function must have two parameters. 4. First parameter must be pointer GaThread (GaThread*). 5. Second parameter must be pointer to void (void *). |
#define ATOMIC_DEC | ( | VALUE | ) | InterlockedDecrement( (LONG*)&VALUE ) |
ATOMIC_DEC
macro atomically decrements VALUE
by one and returns new value.
VALUE | variable which is decremented. |
#define ATOMIC_DEC | ( | VALUE | ) | _SYSTEM_OR_COMPILER_SPECIFIC_ |
ATOMIC_DEC
macro atomically decrements VALUE
by one and returns new value.
VALUE | variable which is decremented. |
#define ATOMIC_INC | ( | VALUE | ) | InterlockedIncrement( (LONG*)&VALUE ) |
ATOMIC_INC
macro atomically increments VALUE
by one and returns new value.
VALUE | variable which is incremented. |
#define ATOMIC_INC | ( | VALUE | ) | _SYSTEM_OR_COMPILER_SPECIFIC_ |
ATOMIC_INC
macro atomically increments VALUE
by one and returns new value.
VALUE | variable which is incremented. |
#define DEFINE_SYNC_CLASS |
Value:
protected: mutable Threading::GaCriticalSection _synchronizator; \ public: Threading::GaCriticalSection* GACALL GetSynchronizator() const \ { return &_synchronizator; }
DEFINE_SYNC_CLASS
macro inserts members to class which are needed to synchronize access to an object. Synchronization is don by using LOCK_OBJECT
and LOCK_THIS_OBJECT
macros.
#define LOCK | ( | LOCK_NAME | ) | ( LOCK_NAME ).Lock() |
Macro is used to acquire access to critical section protected by synchronization object (GaSectionLock and GaCriticalSection).
LOCK_NAME | synchronization object. |
#define LOCK_OBJECT | ( | LOCK_NAME, | |||
OBJECT | ) | Threading::GaSectionLock LOCK_NAME( ( OBJECT )->GetSynchronizator(), true ) |
Macro acquires access to an object with built-in synchronizator and prevents concurrent access. It instantiate GaSectionLock object with name lock and acquire access to the object, when execution leave the scope in which LOCK_OBJECT
is specified, GaSectionLock object is destroyed and access to the locked object is released. Unlocking access to the object before leaving scope can be done by calling UNLOCK(lock_name)
macro.
LOCK_NAME | object which is synchronized. | |
OBJECT | name of GaSectionLock object. |
#define LOCK_THIS_OBJECT | ( | LOCK_NAME | ) | Threading::GaSectionLock LOCK_NAME( &this->_synchronizator, true ) |
Macro acquires access to this and prevents concurrent access. It declares and instantiates GaSectionLock object with name lock and acquire access to this object, when execution leave the scope in which LOCK_OBJECT
is specified, GaSectionLock object is destroyed and access to this object is released. Unlocking access to this before leaving scope can be done by calling UNLOCK(lock_name)
macro.
LOCK_NAME | name of GaSectionLock object. |
#define SPINLOCK | ( | LOCK | ) | while( InterlockedExchange( (LONG*)&LOCK, 1 ) ) |
SPINLOCK
macro defines mechanism of spinlock.
LOCK | variable that is useed as lock. |
#define SPINLOCK | ( | LOCK | ) | _SYSTEM_OR_COMPILER_SPECIFIC_ |
SPINLOCK
macro defines mechanism of spinlock.
LOCK | variable that is useed as lock. |
#define UNLOCK | ( | LOCK_NAME | ) | ( LOCK_NAME ).Unlock() |
Macro is used when thread exits critical section and releases access to synchronization object (GaSectionLock and GaCriticalSection).
LOCK_NAME | synchronization object. |