diff --git a/lib/base/object.cpp b/lib/base/object.cpp index 5d2b31f7c..b77175d8c 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -31,7 +31,7 @@ REGISTER_PRIMITIVE_TYPE(Object); Object::Object(void) : m_References(0) #ifdef _DEBUG - , m_Locked(false) + , m_LockOwner(0) #endif /* _DEBUG */ { } @@ -49,8 +49,15 @@ Object::~Object(void) */ bool Object::OwnsLock(void) const { - // TODO: barrier before reading m_Locked - return (m_Locked && m_LockOwner == boost::this_thread::get_id()); +#ifdef _WIN32 + DWORD tid = InterlockedExchangeAdd(&m_LockOwner, 0); + + return (tid == GetCurrentThreadId()); +#else /* _WIN32 */ + pthread_t tid = __sync_fetch_and_add(&m_LockOwner, 0); + + return (tid == pthread_self()); +#endif /* _WIN32 */ } #endif /* _DEBUG */ diff --git a/lib/base/object.hpp b/lib/base/object.hpp index fbaaf8640..86f96119e 100644 --- a/lib/base/object.hpp +++ b/lib/base/object.hpp @@ -109,8 +109,11 @@ private: mutable ThinMutex m_Mutex; #ifdef _DEBUG - mutable bool m_Locked; - mutable boost::thread::id m_LockOwner; +# ifndef _WIN32 + mutable pthread_t m_LockOwner; +# else /* _WIN32 */ + mutable DWORD m_LockOwner; +# endif /* _WIN32 */ #endif /* _DEBUG */ friend struct ObjectLock; diff --git a/lib/base/objectlock.hpp b/lib/base/objectlock.hpp index 3aa0e39b1..4fd839c5a 100644 --- a/lib/base/objectlock.hpp +++ b/lib/base/objectlock.hpp @@ -62,18 +62,25 @@ public: m_Locked = true; #ifdef _DEBUG - m_Object->m_Locked = true; - // TODO: barrier after writing m_Locked - m_Object->m_LockOwner = boost::this_thread::get_id(); +# ifdef _WIN32 + InterlockedExchange(&m_Object->m_LockOwner, GetCurrentThreadId()); +# else /* _WIN32 */ + __sync_lock_test_and_set(&m_Object->m_LockOwner, pthread_self()); +# endif /* _WIN32 */ #endif /* _DEBUG */ } inline void Unlock(void) { - #ifdef _DEBUG - if (m_Locked) - m_Object->m_Locked = false; - #endif /* _DEBUG */ +#ifdef _DEBUG + if (m_Locked) { +# ifdef _WIN32 + InterlockedExchange(&m_Object->m_Locked, 0); +# else /* _WIN32 */ + __sync_lock_test_and_set(&m_Object->m_LockOwner, 0); +# endif /* _WIN32 */ + } +#endif /* _DEBUG */ if (m_Locked) { m_Object->m_Mutex.Unlock(); diff --git a/lib/base/unix.hpp b/lib/base/unix.hpp index adb61b236..4163aa280 100644 --- a/lib/base/unix.hpp +++ b/lib/base/unix.hpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include