diff --git a/common/include/Pcsx2Types.h b/common/include/Pcsx2Types.h index 81e08afe68..4371f1f9cf 100644 --- a/common/include/Pcsx2Types.h +++ b/common/include/Pcsx2Types.h @@ -199,4 +199,15 @@ typedef union _s128_t #endif +// On linux sizes of long depends on the architecture (4B/x86 vs 86/amd64) +// Windows compiler requires int/long type for _InterlockedExchange* function. +// The best would be to port all _InterlockedExchange function to use +// Theading::Atomic* function. Unfortunately Win version is not happy, until +// code is properly fixed let's use a basic type alias. +#ifdef WIN32 +typedef long vol_t; +#else +typedef s32 vol_t; +#endif + #endif diff --git a/common/include/Utilities/General.h b/common/include/Utilities/General.h index ce534f058b..71a6a58547 100644 --- a/common/include/Utilities/General.h +++ b/common/include/Utilities/General.h @@ -111,7 +111,7 @@ protected: class BaseDeletableObject : public virtual IDeletableObject { protected: - volatile s32 m_IsBeingDeleted; + volatile vol_t m_IsBeingDeleted; public: BaseDeletableObject(); diff --git a/common/include/Utilities/PersistentThread.h b/common/include/Utilities/PersistentThread.h index 59fb7da1f0..247020dbd8 100644 --- a/common/include/Utilities/PersistentThread.h +++ b/common/include/Utilities/PersistentThread.h @@ -103,7 +103,7 @@ namespace Threading MutexRecursive m_mtx_start; // used to lock the Start() code from starting simultaneous threads accidentally. Mutex m_mtx_ThreadName; - volatile s32 m_detached; // a boolean value which indicates if the m_thread handle is valid + volatile vol_t m_detached; // a boolean value which indicates if the m_thread handle is valid volatile s32 m_running; // set true by Start(), and set false by Cancel(), Block(), etc. // exception handle, set non-NULL if the thread terminated with an exception diff --git a/common/src/Utilities/Mutex.cpp b/common/src/Utilities/Mutex.cpp index 2462ac4a05..fdcd5b7f19 100644 --- a/common/src/Utilities/Mutex.cpp +++ b/common/src/Utilities/Mutex.cpp @@ -23,7 +23,7 @@ namespace Threading { - static s32 _attr_refcount = 0; + static vol_t _attr_refcount = 0; static pthread_mutexattr_t _attr_recursive; } @@ -69,7 +69,7 @@ Threading::Mutex::~Mutex() throw() Threading::MutexRecursive::MutexRecursive() : Mutex( false ) { - if( Threading::AtomicIncrement( _attr_refcount ) == 1 ) + if( _InterlockedIncrement( &_attr_refcount ) == 1 ) { if( 0 != pthread_mutexattr_init( &_attr_recursive ) ) throw Exception::OutOfMemory(L"Recursive mutexing attributes"); @@ -83,7 +83,7 @@ Threading::MutexRecursive::MutexRecursive() : Mutex( false ) Threading::MutexRecursive::~MutexRecursive() throw() { - if( Threading::AtomicDecrement( _attr_refcount ) == 0 ) + if( _InterlockedDecrement( &_attr_refcount ) == 0 ) pthread_mutexattr_destroy( &_attr_recursive ); } diff --git a/common/src/Utilities/ThreadTools.cpp b/common/src/Utilities/ThreadTools.cpp index 9ffde2675d..87f071cbdb 100644 --- a/common/src/Utilities/ThreadTools.cpp +++ b/common/src/Utilities/ThreadTools.cpp @@ -291,7 +291,7 @@ bool Threading::pxThread::Detach() { AffinityAssert_DisallowFromSelf(pxDiagSpot); - if( Threading::AtomicExchange( m_detached, true ) ) return false; + if( _InterlockedExchange( &m_detached, true ) ) return false; pthread_detach( m_thread ); return true; } @@ -789,14 +789,6 @@ void Threading::WaitEvent::Wait() // Note: For all of these atomic operations below to be atomic, the variables need to be 4-byte // aligned. Read: http://msdn.microsoft.com/en-us/library/ms684122%28v=vs.85%29.aspx -// On linux sizes of long depends on the architecture (4B/x86 vs 86/amd64) -// Windows compiler requires int/long type for those instrinsics -#ifdef WIN32 -typedef long vol_t; -#else -typedef s32 vol_t; -#endif - __fi u32 Threading::AtomicRead(volatile u32& Target) { return Target; // Properly-aligned 32-bit reads are atomic } diff --git a/common/src/Utilities/wxHelpers.cpp b/common/src/Utilities/wxHelpers.cpp index 9a0f4c584f..a0d189e3b4 100644 --- a/common/src/Utilities/wxHelpers.cpp +++ b/common/src/Utilities/wxHelpers.cpp @@ -49,7 +49,7 @@ pxDialogCreationFlags pxDialogFlags() // bool BaseDeletableObject::MarkForDeletion() { - return !Threading::AtomicExchange( m_IsBeingDeleted, true ); + return !_InterlockedExchange( &m_IsBeingDeleted, true ); } void BaseDeletableObject::DeleteSelf()