Add missing barriers for Object::m_LockOwner

refs #7648
This commit is contained in:
Gunnar Beutner 2014-11-12 12:32:14 +01:00
parent dfd24e6359
commit c5a5d1833b
4 changed files with 29 additions and 13 deletions

View File

@ -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 */

View File

@ -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;

View File

@ -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();

View File

@ -36,7 +36,6 @@
#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>