summaryrefslogtreecommitdiff
path: root/src/mutex.hpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:08:43 +0900
committerMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:08:43 +0900
commit1e01248efc113cc9389f795157400a634730823e (patch)
tree5b321c0540001b6c1f7eab659e4cefec67dfcf96 /src/mutex.hpp
parenta55458399f9e54f8384eda174d405ee85d490c45 (diff)
XS_CTX_REENTRANT option added
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/mutex.hpp')
-rw-r--r--src/mutex.hpp52
1 files changed, 34 insertions, 18 deletions
diff --git a/src/mutex.hpp b/src/mutex.hpp
index 118b5ef..fc75bed 100644
--- a/src/mutex.hpp
+++ b/src/mutex.hpp
@@ -37,28 +37,34 @@ namespace xs
class mutex_t
{
public:
- inline mutex_t ()
+ inline mutex_t (bool fake_ = false) :
+ fake (fake_)
{
- InitializeCriticalSection (&cs);
+ if (!fake)
+ InitializeCriticalSection (&cs);
}
inline ~mutex_t ()
{
- DeleteCriticalSection (&cs);
+ if (!fake)
+ DeleteCriticalSection (&cs);
}
inline void lock ()
{
- EnterCriticalSection (&cs);
+ if (!fake)
+ EnterCriticalSection (&cs);
}
inline void unlock ()
{
- LeaveCriticalSection (&cs);
+ if (!fake)
+ LeaveCriticalSection (&cs);
}
private:
+ bool fake;
CRITICAL_SECTION cs;
// Disable copy construction and assignment.
@@ -78,36 +84,46 @@ namespace xs
class mutex_t
{
public:
- inline mutex_t ()
+ inline mutex_t (bool fake_ = false) :
+ fake (fake_)
{
- int rc = pthread_mutex_init (&mutex, NULL);
- if (rc)
- posix_assert (rc);
+ if (!fake) {
+ int rc = pthread_mutex_init (&mutex, NULL);
+ if (rc)
+ posix_assert (rc);
+ }
}
inline ~mutex_t ()
{
- int rc = pthread_mutex_destroy (&mutex);
- if (rc)
- posix_assert (rc);
+ if (!fake) {
+ int rc = pthread_mutex_destroy (&mutex);
+ if (rc)
+ posix_assert (rc);
+ }
}
inline void lock ()
{
- int rc = pthread_mutex_lock (&mutex);
- if (rc)
- posix_assert (rc);
+ if (!fake) {
+ int rc = pthread_mutex_lock (&mutex);
+ if (rc)
+ posix_assert (rc);
+ }
}
inline void unlock ()
{
- int rc = pthread_mutex_unlock (&mutex);
- if (rc)
- posix_assert (rc);
+ if (!fake) {
+ int rc = pthread_mutex_unlock (&mutex);
+ if (rc)
+ posix_assert (rc);
+ }
}
private:
+ bool fake;
pthread_mutex_t mutex;
// Disable copy construction and assignment.