Common: port code to std::atomic

This commit is contained in:
Gregory Hainaut 2016-02-22 22:14:29 +01:00
parent ca8955daf3
commit 5ca92ecd67
5 changed files with 12 additions and 12 deletions

View File

@ -111,7 +111,7 @@ protected:
class BaseDeletableObject : public virtual IDeletableObject
{
protected:
volatile vol_t m_IsBeingDeleted;
std::atomic<bool> m_IsBeingDeleted;
public:
BaseDeletableObject();

View File

@ -103,8 +103,8 @@ namespace Threading
MutexRecursive m_mtx_start; // used to lock the Start() code from starting simultaneous threads accidentally.
Mutex m_mtx_ThreadName;
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.
std::atomic<bool> m_detached; // a boolean value which indicates if the m_thread handle is valid
std::atomic<bool> 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
// Use RethrowException() to re-throw the exception using its original exception type.
@ -243,8 +243,8 @@ namespace Threading
class BaseTaskThread : public pxThread
{
protected:
volatile bool m_Done;
volatile bool m_TaskPending;
std::atomic<bool> m_Done;
std::atomic<bool> m_TaskPending;
Semaphore m_post_TaskComplete;
Mutex m_lock_TaskComplete;

View File

@ -23,7 +23,7 @@
namespace Threading
{
static vol_t _attr_refcount = 0;
static std::atomic<int> _attr_refcount(0);
static pthread_mutexattr_t _attr_recursive;
}
@ -120,7 +120,7 @@ Threading::Mutex::~Mutex() throw()
Threading::MutexRecursive::MutexRecursive() : Mutex( false )
{
if( _InterlockedIncrement( &_attr_refcount ) == 1 )
if( _attr_refcount.fetch_add(1) == 1 )
{
if( 0 != pthread_mutexattr_init( &_attr_recursive ) )
throw Exception::OutOfMemory(L"Recursive mutexing attributes");
@ -134,7 +134,7 @@ Threading::MutexRecursive::MutexRecursive() : Mutex( false )
Threading::MutexRecursive::~MutexRecursive() throw()
{
if( _InterlockedDecrement( &_attr_refcount ) == 0 )
if( _attr_refcount.fetch_sub(1) == 0 )
pthread_mutexattr_destroy( &_attr_recursive );
}

View File

@ -291,7 +291,7 @@ bool Threading::pxThread::Detach()
{
AffinityAssert_DisallowFromSelf(pxDiagSpot);
if( _InterlockedExchange( &m_detached, true ) ) return false;
if( m_detached.exchange(true) ) return false;
pthread_detach( m_thread );
return true;
}
@ -386,7 +386,7 @@ bool Threading::pxThread::IsSelf() const
bool Threading::pxThread::IsRunning() const
{
return !!m_running;
return m_running;
}
void Threading::pxThread::AddListener( EventListener_Thread& evt )
@ -669,7 +669,7 @@ void Threading::pxThread::OnCleanupInThread()
m_native_handle = 0;
m_native_id = 0;
m_evtsrc_OnDelete.Dispatch( 0 );
}

View File

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