Object::Object(void)
: m_References(0)
#ifdef _DEBUG
- , m_Locked(false)
+ , m_LockOwner(0)
#endif /* _DEBUG */
{ }
*/
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 */
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;
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();
#include <sys/wait.h>
#include <glob.h>
#include <dlfcn.h>
-#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <sys/time.h>