From 7c2dfc65b15f62751470778284b325734d0a241b Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 16 Feb 2012 10:09:36 +0900 Subject: Socket re-entrancy rewritten The inspiration for this re-write came form John Skaller's patch. Adding him to Credits section of the AUTHORS file. Signed-off-by: Martin Sustrik --- src/mutex.hpp | 53 +++++++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) (limited to 'src/mutex.hpp') diff --git a/src/mutex.hpp b/src/mutex.hpp index fc75bed..c0a2cc9 100644 --- a/src/mutex.hpp +++ b/src/mutex.hpp @@ -37,34 +37,28 @@ namespace xs class mutex_t { public: - inline mutex_t (bool fake_ = false) : - fake (fake_) + inline mutex_t () { - if (!fake) - InitializeCriticalSection (&cs); + InitializeCriticalSection (&cs); } inline ~mutex_t () { - if (!fake) - DeleteCriticalSection (&cs); + DeleteCriticalSection (&cs); } inline void lock () { - if (!fake) - EnterCriticalSection (&cs); + EnterCriticalSection (&cs); } inline void unlock () { - if (!fake) - LeaveCriticalSection (&cs); + LeaveCriticalSection (&cs); } private: - bool fake; CRITICAL_SECTION cs; // Disable copy construction and assignment. @@ -84,46 +78,36 @@ namespace xs class mutex_t { public: - inline mutex_t (bool fake_ = false) : - fake (fake_) + inline mutex_t () { - if (!fake) { - int rc = pthread_mutex_init (&mutex, NULL); - if (rc) - posix_assert (rc); - } + int rc = pthread_mutex_init (&mutex, NULL); + if (rc) + posix_assert (rc); } inline ~mutex_t () { - if (!fake) { - int rc = pthread_mutex_destroy (&mutex); - if (rc) - posix_assert (rc); - } + int rc = pthread_mutex_destroy (&mutex); + if (rc) + posix_assert (rc); } inline void lock () { - if (!fake) { - int rc = pthread_mutex_lock (&mutex); - if (rc) - posix_assert (rc); - } + int rc = pthread_mutex_lock (&mutex); + if (rc) + posix_assert (rc); } inline void unlock () { - if (!fake) { - int rc = pthread_mutex_unlock (&mutex); - if (rc) - posix_assert (rc); - } + int rc = pthread_mutex_unlock (&mutex); + if (rc) + posix_assert (rc); } private: - bool fake; pthread_mutex_t mutex; // Disable copy construction and assignment. @@ -136,3 +120,4 @@ namespace xs #endif #endif + -- cgit v1.2.3