windows build take3: revert previous commit

Use back _Interlocked* function
Use vol_t type for all variables that uses _Interlocked* function
    (so it is compatible with 64 bits)
This commit is contained in:
Gregory Hainaut 2015-01-18 19:25:46 +01:00
parent 6d4039cc85
commit 29ef99d2d1
6 changed files with 18 additions and 15 deletions

View File

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

View File

@ -111,7 +111,7 @@ protected:
class BaseDeletableObject : public virtual IDeletableObject
{
protected:
volatile s32 m_IsBeingDeleted;
volatile vol_t m_IsBeingDeleted;
public:
BaseDeletableObject();

View File

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

View File

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

View File

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

View File

@ -49,7 +49,7 @@ pxDialogCreationFlags pxDialogFlags()
//
bool BaseDeletableObject::MarkForDeletion()
{
return !Threading::AtomicExchange( m_IsBeingDeleted, true );
return !_InterlockedExchange( &m_IsBeingDeleted, true );
}
void BaseDeletableObject::DeleteSelf()