00001
#ifndef PtMutex_H
00002
#define PtMutex_H
00003
00004
#include "ILockable.h"
00005
#include "Exceptions.h"
00006
#include "PtCondition.h"
00007
00008
#include <pthread.h>
00009
00010 BOREALIS_NAMESPACE_BEGIN;
00011
00012 class PtMutex :
public ILockable
00013 {
00014
public:
00015
PtMutex()
00016
throw (::std::exception);
00017
00018
virtual ~PtMutex()
00019
throw (::std::exception);
00020
00021
void lock()
00022
throw (::std::exception);
00023
00024
void unlock()
00025
throw (::std::exception);
00026
00027
bool try_lock()
00028
throw (::std::exception);
00029
00030
void waitCond(
PtCondition & cond)
00031
throw (::std::exception);
00032
00033
#ifdef SM_VERIFY_LOCKS
00034
00035
00036
bool getHolder(pthread_t & tid)
00037
throw (exception);
00038
00039
00040
00041
00042
void ensureHeldByCaller(
bool doAbort)
const
00043
throw (exception);
00044
#endif
00045
00046
private:
00047 pthread_mutex_t _mtx;
00048
00049
#ifdef SM_VERIFY_LOCKS
00050
pthread_mutex_t _guard;
00051 pthread_t _holder;
00052
bool _held;
00053
#endif
00054
};
00055
00056 BOREALIS_NAMESPACE_END;
00057
00058
#endif
00059
00060
00061
#ifdef SM_VERIFY_LOCKS
00062
#define VERIFY_CALLER_HOLDS_LOCK(M) M.ensureHeldByCaller(true);
00063
#else
00064 #define VERIFY_CALLER_HOLDS_LOCK(M)
00065
#endif