Cross platform mutex structure for thread safe operations. This structure has been defined to work in both Windows and Linux operating systems.
More...
#include <mutex.h>
List of all members.
Classes |
class | CScopedPtr |
| Equivalent of the ScopedPtr class, but for constant data. More...
|
class | ScopedLock |
| Class for enabling a Mutex within a specific program scope which will unlock the mutex when out of scope (when object is destroyed). More...
|
class | ScopedPtr |
| Template class for making a pointer to some data that that needs protection by a mutex. When the Ptr goes out of scope or is deleted the mutex is automatically released. More...
|
union | SemUnion |
| Simple union structure used to create a semaphore (Global Named Mutex) in a posix compliant OS (Linux). More...
|
Public Member Functions |
| Mutex (const std::string &name=std::string()) |
| Constructor. This initializes the mutex file descripters for use.
|
| ~Mutex () |
| Destructor. This closes any mutex that may be open.
|
void | Create (const std::string &name) |
| Creates mutex using a global name.
|
bool | Lock (unsigned long wait=INFINITE) const |
| Call this function to enter the critical area that the mutex is in.
|
void | Unlock () const |
| Call this function to leave the critical area that the mutex is in.
|
bool | IsLocked () const |
Protected Types |
typedef pthread_t | ID |
Protected Attributes |
bool | mCreateFlag |
std::string | mName |
| Name of the global mutex.
|
int | mSemID |
| Shared semaphore file descriptor.
|
key_t | mSemKey |
| Key structure used for semaphore.
|
union Mutex::SemUnion | mSemUnion |
| Contains semaphore information.
|
pthread_mutex_t | mMutex |
| Standard pthread mutex.
|
volatile ID | mThreadID |
| ID of the calling thread which locked the mutex.
|
Static Protected Attributes |
static unsigned int | mCount = 0 |
| The mutex number.
|
Detailed Description
Cross platform mutex structure for thread safe operations. This structure has been defined to work in both Windows and Linux operating systems.
In windows you can assign a name to the Mutex and make it global (similar to a semaphore), however this support is not available in linux.
Definition at line 75 of file mutex.h.
Member Typedef Documentation
Constructor & Destructor Documentation
Mutex::Mutex |
( |
const std::string & |
name = std::string() ) |
|
Constructor. This initializes the mutex file descripters for use.
- Parameters:
-
[in] | name | Name of mutex (GLOBAL NAMESPACE, should be an integer for best portability between Windows and Linux. |
Definition at line 128 of file mutex.cpp.
Destructor. This closes any mutex that may be open.
Definition at line 149 of file mutex.cpp.
Member Function Documentation
void Mutex::Create |
( |
const std::string & |
name ) |
|
Creates mutex using a global name.
- Parameters:
-
[in] | name | Name of mutex (GLOBAL NAMESPACE, should be an integer for best portability between Windows and Linux. If empty string, then a regulur mutex within this process is created. |
Definition at line 190 of file mutex.cpp.
bool Mutex::IsLocked |
( |
) |
const |
- Returns:
- True if the mutex has been locked in the current thread/scope, otherwise false.
Definition at line 408 of file mutex.cpp.
bool Mutex::Lock |
( |
unsigned long |
wait = INFINITE ) |
const |
Call this function to enter the critical area that the mutex is in.
- Parameters:
-
[in] | wait | How long to wait for an event to occur allowing access to the critical section of code you want to protect with a mutex. Value is in milliseconds. |
- Returns:
- True if mutex was enabled, and you have entered the critical section of memory, false otherwise.
< Semaphore buffer.
Definition at line 296 of file mutex.cpp.
void Mutex::Unlock |
( |
) |
const |
Call this function to leave the critical area that the mutex is in.
< Semaphore buffer.
Definition at line 365 of file mutex.cpp.
Member Data Documentation
The mutex number.
Definition at line 375 of file mutex.h.
Standard pthread mutex.
Definition at line 367 of file mutex.h.
Name of the global mutex.
Definition at line 363 of file mutex.h.
Shared semaphore file descriptor.
Definition at line 364 of file mutex.h.
Key structure used for semaphore.
Definition at line 365 of file mutex.h.
Contains semaphore information.
Definition at line 366 of file mutex.h.
ID of the calling thread which locked the mutex.
Definition at line 374 of file mutex.h.
The documentation for this class was generated from the following files:
- C:/Active/libraries/cxutils/2.0/include/cxutils/mutex.h
- C:/Active/libraries/cxutils/2.0/src/cxutils/mutex.cpp