annotate stk/include/Mutex.h @ 0:4606bd505630 tip

first import
author Fiore Martin <f.martin@qmul.ac.uk>
date Sat, 13 Jun 2015 15:08:10 +0100
parents
children
rev   line source
f@0 1 #ifndef STK_MUTEX_H
f@0 2 #define STK_MUTEX_H
f@0 3
f@0 4 #include "Stk.h"
f@0 5
f@0 6 #if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__))
f@0 7
f@0 8 #include <pthread.h>
f@0 9 typedef pthread_mutex_t MUTEX;
f@0 10 typedef pthread_cond_t CONDITION;
f@0 11
f@0 12 #elif defined(__OS_WINDOWS__)
f@0 13
f@0 14 #include <windows.h>
f@0 15 #include <process.h>
f@0 16 typedef CRITICAL_SECTION MUTEX;
f@0 17 typedef HANDLE CONDITION;
f@0 18
f@0 19 #endif
f@0 20
f@0 21 namespace stk {
f@0 22
f@0 23 /***************************************************/
f@0 24 /*! \class Mutex
f@0 25 \brief STK mutex class.
f@0 26
f@0 27 This class provides a uniform interface for
f@0 28 cross-platform mutex use. On Linux and IRIX
f@0 29 systems, the pthread library is used. Under
f@0 30 Windows, critical sections are used.
f@0 31
f@0 32 by Perry R. Cook and Gary P. Scavone, 1995--2014.
f@0 33 */
f@0 34 /***************************************************/
f@0 35
f@0 36 class Mutex : public Stk
f@0 37 {
f@0 38 public:
f@0 39 //! Default constructor.
f@0 40 Mutex();
f@0 41
f@0 42 //! Class destructor.
f@0 43 ~Mutex();
f@0 44
f@0 45 //! Lock the mutex.
f@0 46 void lock(void);
f@0 47
f@0 48 //! Unlock the mutex.
f@0 49 void unlock(void);
f@0 50
f@0 51 //! Wait indefinitely on the mutex condition variable.
f@0 52 /*!
f@0 53 The mutex must be locked before calling this function, and then
f@0 54 subsequently unlocked after this function returns.
f@0 55 */
f@0 56 void wait(void);
f@0 57
f@0 58 //! Signal the condition variable.
f@0 59 /*!
f@0 60 The mutex must be locked before calling this function, and then
f@0 61 subsequently unlocked after this function returns.
f@0 62 */
f@0 63 void signal(void);
f@0 64
f@0 65 protected:
f@0 66
f@0 67 MUTEX mutex_;
f@0 68 CONDITION condition_;
f@0 69
f@0 70 };
f@0 71
f@0 72 } // stk namespace
f@0 73
f@0 74 #endif