mirror of
https://github.com/thestk/stk
synced 2026-01-11 20:11:52 +00:00
Version 4.2.0
This commit is contained in:
committed by
Stephen Sinclair
parent
cf06b7598b
commit
a6381b9d38
70
include/Mutex.h
Normal file
70
include/Mutex.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/***************************************************/
|
||||
/*! \class Mutex
|
||||
\brief STK mutex class.
|
||||
|
||||
This class provides a uniform interface for
|
||||
cross-platform mutex use. On Linux and IRIX
|
||||
systems, the pthread library is used. Under
|
||||
Windows, critical sections are used.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#ifndef STK_MUTEX_H
|
||||
#define STK_MUTEX_H
|
||||
|
||||
#include "Stk.h"
|
||||
|
||||
#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__))
|
||||
|
||||
#include <pthread.h>
|
||||
typedef pthread_mutex_t MUTEX;
|
||||
typedef pthread_cond_t CONDITION;
|
||||
|
||||
#elif defined(__OS_WINDOWS__)
|
||||
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
typedef CRITICAL_SECTION MUTEX;
|
||||
typedef HANDLE CONDITION;
|
||||
|
||||
#endif
|
||||
|
||||
class Mutex : public Stk
|
||||
{
|
||||
public:
|
||||
//! Default constructor.
|
||||
Mutex();
|
||||
|
||||
//! Class destructor.
|
||||
~Mutex();
|
||||
|
||||
//! Lock the mutex.
|
||||
void lock(void);
|
||||
|
||||
//! Unlock the mutex.
|
||||
void unlock(void);
|
||||
|
||||
//! Wait indefinitely on the mutex condition variable.
|
||||
/*!
|
||||
The mutex must be locked before calling this function, and then
|
||||
subsequently unlocked after this function returns.
|
||||
*/
|
||||
void wait(void);
|
||||
|
||||
//! Signal the condition variable.
|
||||
/*!
|
||||
The mutex must be locked before calling this function, and then
|
||||
subsequently unlocked after this function returns.
|
||||
*/
|
||||
void signal(void);
|
||||
|
||||
protected:
|
||||
|
||||
MUTEX mutex_;
|
||||
CONDITION condition_;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user