gui: use std::atomic bool to manage the gui

V2: Don't use 64 bits atomic (I'm not sure it is legal on 32 bits)
Note: Clang-3.7 fails to link
This commit is contained in:
Gregory Hainaut 2016-02-22 20:15:15 +01:00
parent e5d4f2c24f
commit 97cc468509
7 changed files with 23 additions and 21 deletions

View File

@ -1319,11 +1319,11 @@ void AppSaveSettings()
// If multiple SaveSettings messages are requested, we want to ignore most of them.
// Saving settings once when the GUI is idle should be fine. :)
static u32 isPosted = false;
static std::atomic<bool> isPosted(false);
if( !wxThread::IsMain() )
{
if( !AtomicExchange(isPosted, true) )
if( !isPosted.exchange(true) )
wxGetApp().PostIdleMethod( AppSaveSettings );
return;
@ -1335,7 +1335,7 @@ void AppSaveSettings()
SaveVmSettings();
SaveRegSettings(); // save register because of PluginsFolder change
AtomicExchange( isPosted, false );
isPosted = false;
}

View File

@ -483,7 +483,7 @@ void AppCoreThread::OnResumeInThread( bool isSuspended )
GetCorePlugins().Close( PluginId_CDVD );
CDVDsys_ChangeSource( g_Conf->CdvdSource );
cdvdCtrlTrayOpen();
m_resetCdvd = false;
m_resetCdvd = false;
}
_parent::OnResumeInThread( isSuspended );

View File

@ -123,12 +123,12 @@ class AppCoreThread : public SysCoreThread
typedef SysCoreThread _parent;
protected:
volatile bool m_resetCdvd;
std::atomic<bool> m_resetCdvd;
public:
AppCoreThread();
virtual ~AppCoreThread() throw();
void ResetCdvd() { m_resetCdvd = true; }
virtual void Suspend( bool isBlocking=false );

View File

@ -77,7 +77,7 @@ class ConsoleTestThread : public Threading::pxThread
typedef pxThread _parent;
protected:
volatile bool m_done;
std::atomic<bool> m_done;
void ExecuteTaskInThread();
public:
@ -176,22 +176,22 @@ protected:
int m_flushevent_counter;
bool m_FlushRefreshLocked;
// ----------------------------------------------------------------------------
// Queue State Management Vars
// ----------------------------------------------------------------------------
// Boolean indicating if a flush message is already in the Main message queue. Used
// to prevent spamming the main thread with redundant messages.
volatile bool m_pendingFlushMsg;
std::atomic<bool> m_pendingFlushMsg;
// This is a counter of the number of threads waiting for the Queue to flush.
volatile int m_WaitingThreadsForFlush;
std::atomic<int> m_WaitingThreadsForFlush;
// Indicates to the main thread if a child thread is actively writing to the log. If
// true the main thread will sleep briefly to allow the child a chance to accumulate
// more messages (helps avoid rapid successive flushes on high volume logging).
volatile bool m_ThreadedLogInQueue;
std::atomic<bool> m_ThreadedLogInQueue;
// Used by threads waiting on the queue to flush.
Semaphore m_sem_QueueFlushed;
@ -258,6 +258,6 @@ protected:
void OnMoveAround( wxMoveEvent& evt );
void OnResize( wxSizeEvent& evt );
void OnActivate( wxActivateEvent& evt );
void OnLoggingChanged();
};

View File

@ -158,7 +158,7 @@ void SysExecEvent::PostResult() const
// --------------------------------------------------------------------------------------
pxEvtQueue::pxEvtQueue()
{
AtomicExchange( m_Quitting, false );
m_Quitting = false;
m_qpc_Start = 0;
}
@ -171,7 +171,7 @@ pxEvtQueue::pxEvtQueue()
void pxEvtQueue::ShutdownQueue()
{
if( m_Quitting ) return;
AtomicExchange( m_Quitting, true );
m_Quitting = true;
m_wakeup.Post();
}

View File

@ -40,7 +40,7 @@ bool States_isSlotUsed(int num)
// FIXME : Use of the IsSavingOrLoading flag is mostly a hack until we implement a
// complete thread to manage queuing savestate tasks, and zipping states to disk. --air
static volatile u32 IsSavingOrLoading = false;
static std::atomic<bool> IsSavingOrLoading(false);
class SysExecEvent_ClearSavingLoadingFlag : public SysExecEvent
{
@ -57,7 +57,7 @@ public:
protected:
void InvokeEvent()
{
AtomicExchange(IsSavingOrLoading, false);
IsSavingOrLoading = false;
}
};
@ -73,7 +73,7 @@ void States_FreezeCurrentSlot()
return;
}
if( wxGetApp().HasPendingSaves() || AtomicExchange(IsSavingOrLoading, true) )
if( wxGetApp().HasPendingSaves() || IsSavingOrLoading.exchange(true) )
{
Console.WriteLn( "Load or save action is already pending." );
return;
@ -94,7 +94,7 @@ void _States_DefrostCurrentSlot( bool isFromBackup )
return;
}
if( AtomicExchange(IsSavingOrLoading, true) )
if( IsSavingOrLoading.exchange(true) )
{
Console.WriteLn( "Load or save action is already pending." );
return;

View File

@ -204,11 +204,13 @@ protected:
Threading::MutexRecursive m_mtx_pending;
Threading::Semaphore m_wakeup;
wxThreadIdType m_OwnerThreadId;
volatile u32 m_Quitting;
std::atomic<bool> m_Quitting;
// Used for performance measuring the execution of individual events,
// and also for detecting deadlocks during message processing.
volatile u64 m_qpc_Start;
// Clang-3.7 failed to link (maybe 64 bits atomic isn't supported on 32 bits)
// std::atomic<unsigned long long> m_qpc_Start;
u64 m_qpc_Start;
public:
pxEvtQueue();