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. // If multiple SaveSettings messages are requested, we want to ignore most of them.
// Saving settings once when the GUI is idle should be fine. :) // 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( !wxThread::IsMain() )
{ {
if( !AtomicExchange(isPosted, true) ) if( !isPosted.exchange(true) )
wxGetApp().PostIdleMethod( AppSaveSettings ); wxGetApp().PostIdleMethod( AppSaveSettings );
return; return;
@ -1335,7 +1335,7 @@ void AppSaveSettings()
SaveVmSettings(); SaveVmSettings();
SaveRegSettings(); // save register because of PluginsFolder change 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 ); GetCorePlugins().Close( PluginId_CDVD );
CDVDsys_ChangeSource( g_Conf->CdvdSource ); CDVDsys_ChangeSource( g_Conf->CdvdSource );
cdvdCtrlTrayOpen(); cdvdCtrlTrayOpen();
m_resetCdvd = false; m_resetCdvd = false;
} }
_parent::OnResumeInThread( isSuspended ); _parent::OnResumeInThread( isSuspended );

View File

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

View File

@ -77,7 +77,7 @@ class ConsoleTestThread : public Threading::pxThread
typedef pxThread _parent; typedef pxThread _parent;
protected: protected:
volatile bool m_done; std::atomic<bool> m_done;
void ExecuteTaskInThread(); void ExecuteTaskInThread();
public: public:
@ -176,22 +176,22 @@ protected:
int m_flushevent_counter; int m_flushevent_counter;
bool m_FlushRefreshLocked; bool m_FlushRefreshLocked;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Queue State Management Vars // Queue State Management Vars
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Boolean indicating if a flush message is already in the Main message queue. Used // Boolean indicating if a flush message is already in the Main message queue. Used
// to prevent spamming the main thread with redundant messages. // 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. // 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 // 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 // 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). // 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. // Used by threads waiting on the queue to flush.
Semaphore m_sem_QueueFlushed; Semaphore m_sem_QueueFlushed;
@ -258,6 +258,6 @@ protected:
void OnMoveAround( wxMoveEvent& evt ); void OnMoveAround( wxMoveEvent& evt );
void OnResize( wxSizeEvent& evt ); void OnResize( wxSizeEvent& evt );
void OnActivate( wxActivateEvent& evt ); void OnActivate( wxActivateEvent& evt );
void OnLoggingChanged(); void OnLoggingChanged();
}; };

View File

@ -158,7 +158,7 @@ void SysExecEvent::PostResult() const
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
pxEvtQueue::pxEvtQueue() pxEvtQueue::pxEvtQueue()
{ {
AtomicExchange( m_Quitting, false ); m_Quitting = false;
m_qpc_Start = 0; m_qpc_Start = 0;
} }
@ -171,7 +171,7 @@ pxEvtQueue::pxEvtQueue()
void pxEvtQueue::ShutdownQueue() void pxEvtQueue::ShutdownQueue()
{ {
if( m_Quitting ) return; if( m_Quitting ) return;
AtomicExchange( m_Quitting, true ); m_Quitting = true;
m_wakeup.Post(); 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 // 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 // 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 class SysExecEvent_ClearSavingLoadingFlag : public SysExecEvent
{ {
@ -57,7 +57,7 @@ public:
protected: protected:
void InvokeEvent() void InvokeEvent()
{ {
AtomicExchange(IsSavingOrLoading, false); IsSavingOrLoading = false;
} }
}; };
@ -73,7 +73,7 @@ void States_FreezeCurrentSlot()
return; return;
} }
if( wxGetApp().HasPendingSaves() || AtomicExchange(IsSavingOrLoading, true) ) if( wxGetApp().HasPendingSaves() || IsSavingOrLoading.exchange(true) )
{ {
Console.WriteLn( "Load or save action is already pending." ); Console.WriteLn( "Load or save action is already pending." );
return; return;
@ -94,7 +94,7 @@ void _States_DefrostCurrentSlot( bool isFromBackup )
return; return;
} }
if( AtomicExchange(IsSavingOrLoading, true) ) if( IsSavingOrLoading.exchange(true) )
{ {
Console.WriteLn( "Load or save action is already pending." ); Console.WriteLn( "Load or save action is already pending." );
return; return;

View File

@ -204,11 +204,13 @@ protected:
Threading::MutexRecursive m_mtx_pending; Threading::MutexRecursive m_mtx_pending;
Threading::Semaphore m_wakeup; Threading::Semaphore m_wakeup;
wxThreadIdType m_OwnerThreadId; wxThreadIdType m_OwnerThreadId;
volatile u32 m_Quitting; std::atomic<bool> m_Quitting;
// Used for performance measuring the execution of individual events, // Used for performance measuring the execution of individual events,
// and also for detecting deadlocks during message processing. // 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: public:
pxEvtQueue(); pxEvtQueue();