2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2009-10-21 08:57:05 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-02-09 21:15:56 +00:00
|
|
|
*/
|
2009-10-21 08:57:05 +00:00
|
|
|
|
2009-09-08 12:08:10 +00:00
|
|
|
#pragma once
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-10-07 19:20:11 +00:00
|
|
|
#include <semaphore.h>
|
2009-02-09 21:15:56 +00:00
|
|
|
#include <errno.h> // EBUSY
|
2009-07-03 00:49:40 +00:00
|
|
|
#include <pthread.h>
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2015-11-17 17:35:02 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <mach/semaphore.h>
|
|
|
|
#endif
|
|
|
|
|
2009-04-29 11:47:05 +00:00
|
|
|
#include "Pcsx2Defs.h"
|
2009-09-29 19:16:00 +00:00
|
|
|
#include "ScopedPtr.h"
|
2010-08-06 05:46:09 +00:00
|
|
|
#include "TraceLog.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-12-24 22:22:34 +00:00
|
|
|
#undef Yield // release the burden of windows.h global namespace spam.
|
2009-08-25 15:38:48 +00:00
|
|
|
|
2010-04-27 13:12:03 +00:00
|
|
|
#define AffinityAssert_AllowFrom_MainUI() \
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
pxAssertMsg( wxThread::IsMain(), "Thread affinity violation: Call allowed from main thread only." )
|
|
|
|
|
2010-08-06 05:46:09 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// pxThreadLog / ConsoleLogSource_Threading
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class ConsoleLogSource_Threading : ConsoleLogSource
|
|
|
|
{
|
|
|
|
typedef ConsoleLogSource _parent;
|
|
|
|
|
|
|
|
public:
|
2010-08-16 15:01:13 +00:00
|
|
|
using _parent::IsActive;
|
2010-08-06 05:46:09 +00:00
|
|
|
|
2010-08-16 15:01:13 +00:00
|
|
|
ConsoleLogSource_Threading();
|
2010-08-06 05:46:09 +00:00
|
|
|
|
|
|
|
bool Write( const wxString& thrname, const wxChar* msg ) {
|
2014-06-29 07:05:03 +00:00
|
|
|
return _parent::Write( wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg );
|
2010-08-06 05:46:09 +00:00
|
|
|
}
|
|
|
|
bool Warn( const wxString& thrname, const wxChar* msg ) {
|
2014-06-29 07:05:03 +00:00
|
|
|
return _parent::Warn( wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg );
|
2010-08-06 05:46:09 +00:00
|
|
|
}
|
|
|
|
bool Error( const wxString& thrname, const wxChar* msg ) {
|
2014-06-29 07:05:03 +00:00
|
|
|
return _parent::Error( wxsFormat(L"(thread:%s) ", WX_STR(thrname)) + msg );
|
2010-08-06 05:46:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern ConsoleLogSource_Threading pxConLog_Thread;
|
|
|
|
|
2010-08-16 15:01:13 +00:00
|
|
|
#define pxThreadLog pxConLog_Thread.IsActive() && pxConLog_Thread
|
2010-08-06 05:46:09 +00:00
|
|
|
|
|
|
|
|
2009-12-24 22:22:34 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// PCSX2_THREAD_LOCAL - Defines platform/operating system support for Thread Local Storage
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// For complimentary support for TLS, include Utilities/TlsVariable.inl, and use the
|
|
|
|
// DeclareTls macro in the place of __threadlocal.
|
|
|
|
//
|
2014-12-08 21:26:46 +00:00
|
|
|
//#define PCSX2_THREAD_LOCAL 0 // uncomment this line to force-disable native TLS (useful for testing TlsVariable on windows/linux)
|
2009-12-24 22:22:34 +00:00
|
|
|
|
|
|
|
#ifndef PCSX2_THREAD_LOCAL
|
2015-11-17 17:35:02 +00:00
|
|
|
# define PCSX2_THREAD_LOCAL 1
|
2009-12-24 22:22:34 +00:00
|
|
|
#endif
|
|
|
|
|
2009-11-22 09:47:52 +00:00
|
|
|
class wxTimeSpan;
|
|
|
|
|
|
|
|
namespace Threading
|
|
|
|
{
|
2010-06-19 13:42:32 +00:00
|
|
|
class pxThread;
|
2010-04-27 13:12:03 +00:00
|
|
|
class RwMutex;
|
2009-12-14 12:18:55 +00:00
|
|
|
|
2010-04-27 13:12:03 +00:00
|
|
|
extern void pxTestCancel();
|
2010-06-19 13:42:32 +00:00
|
|
|
extern pxThread* pxGetCurrentThread();
|
2009-12-21 11:52:14 +00:00
|
|
|
extern wxString pxGetCurrentThreadName();
|
2010-01-25 15:31:17 +00:00
|
|
|
extern u64 GetThreadCpuTime();
|
|
|
|
extern u64 GetThreadTicksPerSecond();
|
2009-12-21 11:52:14 +00:00
|
|
|
|
2009-12-27 12:15:21 +00:00
|
|
|
// Yields the current thread and provides cancellation points if the thread is managed by
|
2010-06-19 13:42:32 +00:00
|
|
|
// pxThread. Unmanaged threads use standard Sleep.
|
2009-12-21 11:52:14 +00:00
|
|
|
extern void pxYield( int ms );
|
2009-11-22 09:47:52 +00:00
|
|
|
}
|
|
|
|
|
2009-10-17 18:21:30 +00:00
|
|
|
namespace Exception
|
|
|
|
{
|
2010-06-28 18:03:54 +00:00
|
|
|
class BaseThreadError : public RuntimeError
|
2009-10-17 18:21:30 +00:00
|
|
|
{
|
2010-06-28 18:03:54 +00:00
|
|
|
DEFINE_EXCEPTION_COPYTORS( BaseThreadError, RuntimeError )
|
|
|
|
DEFINE_EXCEPTION_MESSAGES( BaseThreadError )
|
|
|
|
|
2009-10-17 18:21:30 +00:00
|
|
|
public:
|
2010-06-19 13:42:32 +00:00
|
|
|
Threading::pxThread* m_thread;
|
2009-11-22 09:47:52 +00:00
|
|
|
|
2010-06-28 18:03:54 +00:00
|
|
|
protected:
|
|
|
|
BaseThreadError() {
|
|
|
|
m_thread = NULL;
|
|
|
|
}
|
2009-11-22 09:47:52 +00:00
|
|
|
|
2010-06-28 18:03:54 +00:00
|
|
|
public:
|
|
|
|
explicit BaseThreadError( Threading::pxThread* _thread )
|
2009-11-22 09:47:52 +00:00
|
|
|
{
|
|
|
|
m_thread = _thread;
|
2010-06-28 18:03:54 +00:00
|
|
|
m_message_diag = L"An unspecified thread-related error occurred (thread=%s)";
|
2009-11-22 09:47:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 18:03:54 +00:00
|
|
|
explicit BaseThreadError( Threading::pxThread& _thread )
|
2009-11-22 09:47:52 +00:00
|
|
|
{
|
|
|
|
m_thread = &_thread;
|
2010-06-28 18:03:54 +00:00
|
|
|
m_message_diag = L"An unspecified thread-related error occurred (thread=%s)";
|
2009-11-22 09:47:52 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-11-22 09:47:52 +00:00
|
|
|
virtual wxString FormatDiagnosticMessage() const;
|
|
|
|
virtual wxString FormatDisplayMessage() const;
|
|
|
|
|
2010-06-19 13:42:32 +00:00
|
|
|
Threading::pxThread& Thread();
|
|
|
|
const Threading::pxThread& Thread() const;
|
2009-11-22 09:47:52 +00:00
|
|
|
};
|
|
|
|
|
2010-06-28 18:03:54 +00:00
|
|
|
class ThreadCreationError : public BaseThreadError
|
2009-11-22 09:47:52 +00:00
|
|
|
{
|
2010-06-28 18:03:54 +00:00
|
|
|
DEFINE_EXCEPTION_COPYTORS( ThreadCreationError, BaseThreadError )
|
2009-11-22 09:47:52 +00:00
|
|
|
|
2010-06-28 18:03:54 +00:00
|
|
|
public:
|
|
|
|
explicit ThreadCreationError( Threading::pxThread* _thread )
|
2009-11-22 09:47:52 +00:00
|
|
|
{
|
|
|
|
m_thread = _thread;
|
2010-08-06 05:46:09 +00:00
|
|
|
SetBothMsgs( L"Thread creation failure. An unspecified error occurred while trying to create the %s thread." );
|
2009-11-22 09:47:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 18:03:54 +00:00
|
|
|
explicit ThreadCreationError( Threading::pxThread& _thread )
|
2009-11-22 09:47:52 +00:00
|
|
|
{
|
|
|
|
m_thread = &_thread;
|
2010-08-06 05:46:09 +00:00
|
|
|
SetBothMsgs( L"Thread creation failure. An unspecified error occurred while trying to create the %s thread." );
|
2009-11-22 09:47:52 +00:00
|
|
|
}
|
2009-10-17 18:21:30 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-12-24 22:22:34 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
namespace Threading
|
|
|
|
{
|
2009-10-31 19:18:29 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Platform Specific External APIs
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// The following set of documented functions have Linux/Win32 specific implementations,
|
|
|
|
// which are found in WinThreads.cpp and LnxThreads.cpp
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
|
|
|
|
// Releases a timeslice to other threads.
|
|
|
|
extern void Timeslice();
|
|
|
|
|
|
|
|
// For use in spin/wait loops.
|
|
|
|
extern void SpinWait();
|
2010-07-12 19:40:30 +00:00
|
|
|
|
2015-09-11 17:19:00 +00:00
|
|
|
// Use prior to committing data to another thread
|
2010-07-12 19:40:30 +00:00
|
|
|
extern void StoreFence();
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
|
2009-10-19 23:13:22 +00:00
|
|
|
// Optional implementation to enable hires thread/process scheduler for the operating system.
|
|
|
|
// Needed by Windows, but might not be relevant to other platforms.
|
|
|
|
extern void EnableHiresScheduler();
|
|
|
|
extern void DisableHiresScheduler();
|
|
|
|
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
// sleeps the current thread for the given number of milliseconds.
|
|
|
|
extern void Sleep( int ms );
|
|
|
|
|
2009-10-31 19:18:29 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// AtomicExchange / AtomicIncrement
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Our fundamental interlocking functions. All other useful interlocks can be derived
|
|
|
|
// from these little beasties! (these are all implemented internally using cross-platform
|
|
|
|
// implementations of _InterlockedExchange and such)
|
|
|
|
|
2011-08-12 02:31:49 +00:00
|
|
|
extern u32 AtomicRead( volatile u32& Target );
|
|
|
|
extern s32 AtomicRead( volatile s32& Target );
|
2009-10-31 19:18:29 +00:00
|
|
|
extern u32 AtomicExchange( volatile u32& Target, u32 value );
|
|
|
|
extern s32 AtomicExchange( volatile s32& Target, s32 value );
|
2011-08-12 02:31:49 +00:00
|
|
|
extern u32 AtomicExchangeAdd( volatile u32& Target, u32 value );
|
2009-11-24 20:11:43 +00:00
|
|
|
extern s32 AtomicExchangeAdd( volatile s32& Target, s32 value );
|
|
|
|
extern s32 AtomicExchangeSub( volatile s32& Target, s32 value );
|
2011-08-12 02:31:49 +00:00
|
|
|
extern u32 AtomicIncrement( volatile u32& Target );
|
2009-10-31 19:18:29 +00:00
|
|
|
extern s32 AtomicIncrement( volatile s32& Target );
|
2011-08-12 02:31:49 +00:00
|
|
|
extern u32 AtomicDecrement( volatile u32& Target );
|
2009-10-31 19:18:29 +00:00
|
|
|
extern s32 AtomicDecrement( volatile s32& Target );
|
|
|
|
|
2009-11-24 08:32:39 +00:00
|
|
|
extern bool AtomicBitTestAndReset( volatile u32& bitset, u8 bit );
|
2011-08-12 02:31:49 +00:00
|
|
|
extern bool AtomicBitTestAndReset( volatile s32& bitset, u8 bit );
|
2009-11-24 08:32:39 +00:00
|
|
|
|
2010-05-07 03:20:58 +00:00
|
|
|
extern void* _AtomicExchangePointer( volatile uptr& target, uptr value );
|
|
|
|
extern void* _AtomicCompareExchangePointer( volatile uptr& target, uptr value, uptr comparand );
|
2009-10-31 19:18:29 +00:00
|
|
|
|
2010-05-07 03:20:58 +00:00
|
|
|
#define AtomicExchangePointer( dest, src ) _AtomicExchangePointer( (uptr&)dest, (uptr)src )
|
|
|
|
#define AtomicCompareExchangePointer( dest, comp, src ) _AtomicExchangePointer( (uptr&)dest, (uptr)comp, (uptr)src )
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-17 03:43:45 +00:00
|
|
|
// pthread Cond is an evil api that is not suited for Pcsx2 needs.
|
|
|
|
// Let's not use it. Use mutexes and semaphores instead to create waits. (Air)
|
|
|
|
#if 0
|
2009-02-09 21:15:56 +00:00
|
|
|
struct WaitEvent
|
|
|
|
{
|
|
|
|
pthread_cond_t cond;
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
|
|
|
|
WaitEvent();
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
~WaitEvent() throw();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
void Set();
|
|
|
|
void Wait();
|
|
|
|
};
|
2009-07-17 03:43:45 +00:00
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-10-31 19:18:29 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// NonblockingMutex
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// This is a very simple non-blocking mutex, which behaves similarly to pthread_mutex's
|
|
|
|
// trylock(), but without any of the extra overhead needed to set up a structure capable
|
|
|
|
// of blocking waits. It basically optimizes to a single InterlockedExchange.
|
|
|
|
//
|
2009-10-31 19:25:46 +00:00
|
|
|
// Simple use: if TryAcquire() returns false, the Bool is already interlocked by another thread.
|
|
|
|
// If TryAcquire() returns true, you've locked the object and are *responsible* for unlocking
|
2009-10-31 19:18:29 +00:00
|
|
|
// it later.
|
|
|
|
//
|
2009-10-07 19:20:11 +00:00
|
|
|
class NonblockingMutex
|
|
|
|
{
|
|
|
|
protected:
|
2009-10-31 19:18:29 +00:00
|
|
|
volatile int val;
|
2009-10-07 19:20:11 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
NonblockingMutex() : val( false ) {}
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
virtual ~NonblockingMutex() throw() {}
|
2009-10-07 19:20:11 +00:00
|
|
|
|
2009-10-31 19:25:46 +00:00
|
|
|
bool TryAcquire() throw()
|
2009-10-07 19:20:11 +00:00
|
|
|
{
|
2009-10-31 19:18:29 +00:00
|
|
|
return !AtomicExchange( val, true );
|
2009-10-07 19:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsLocked()
|
|
|
|
{ return !!val; }
|
|
|
|
|
|
|
|
void Release()
|
2009-10-31 19:18:29 +00:00
|
|
|
{
|
|
|
|
AtomicExchange( val, false );
|
|
|
|
}
|
2009-10-07 19:20:11 +00:00
|
|
|
};
|
|
|
|
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
class Semaphore
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
protected:
|
2015-11-17 17:35:02 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
semaphore_t m_sema;
|
|
|
|
int m_counter;
|
|
|
|
#else
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
sem_t m_sema;
|
2015-11-17 17:35:02 +00:00
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
public:
|
2009-02-09 21:15:56 +00:00
|
|
|
Semaphore();
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
virtual ~Semaphore() throw();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-28 20:55:53 +00:00
|
|
|
void Reset();
|
2009-02-09 21:15:56 +00:00
|
|
|
void Post();
|
|
|
|
void Post( int multiple );
|
2009-10-17 18:21:30 +00:00
|
|
|
|
2009-11-01 09:27:16 +00:00
|
|
|
void WaitWithoutYield();
|
|
|
|
bool WaitWithoutYield( const wxTimeSpan& timeout );
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
void WaitNoCancel();
|
2009-10-21 08:57:05 +00:00
|
|
|
void WaitNoCancel( const wxTimeSpan& timeout );
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
int Count();
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
void Wait();
|
2009-09-07 21:16:12 +00:00
|
|
|
bool Wait( const wxTimeSpan& timeout );
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2009-10-31 19:18:29 +00:00
|
|
|
class Mutex
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-10-08 18:30:40 +00:00
|
|
|
protected:
|
2009-10-17 18:21:30 +00:00
|
|
|
pthread_mutex_t m_mutex;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-10-08 18:30:40 +00:00
|
|
|
public:
|
2009-10-31 19:18:29 +00:00
|
|
|
Mutex();
|
|
|
|
virtual ~Mutex() throw();
|
2009-10-17 18:21:30 +00:00
|
|
|
virtual bool IsRecursive() const { return false; }
|
2009-10-21 08:57:05 +00:00
|
|
|
|
2009-10-17 18:21:30 +00:00
|
|
|
void Recreate();
|
|
|
|
bool RecreateIfLocked();
|
|
|
|
void Detach();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-10-31 19:25:46 +00:00
|
|
|
void Acquire();
|
|
|
|
bool Acquire( const wxTimeSpan& timeout );
|
|
|
|
bool TryAcquire();
|
2009-10-31 19:18:29 +00:00
|
|
|
void Release();
|
2009-10-17 18:21:30 +00:00
|
|
|
|
2009-11-01 09:27:16 +00:00
|
|
|
void AcquireWithoutYield();
|
|
|
|
bool AcquireWithoutYield( const wxTimeSpan& timeout );
|
2009-10-21 08:57:05 +00:00
|
|
|
|
2009-10-17 18:21:30 +00:00
|
|
|
void Wait();
|
|
|
|
bool Wait( const wxTimeSpan& timeout );
|
2010-04-27 13:12:03 +00:00
|
|
|
void WaitWithoutYield();
|
|
|
|
bool WaitWithoutYield( const wxTimeSpan& timeout );
|
2009-10-21 08:57:05 +00:00
|
|
|
|
2009-10-08 18:30:40 +00:00
|
|
|
protected:
|
|
|
|
// empty constructor used by MutexLockRecursive
|
2009-10-31 19:18:29 +00:00
|
|
|
Mutex( bool ) {}
|
2009-10-08 18:30:40 +00:00
|
|
|
};
|
|
|
|
|
2010-04-27 13:12:03 +00:00
|
|
|
class MutexRecursive : public Mutex
|
2009-10-08 18:30:40 +00:00
|
|
|
{
|
|
|
|
public:
|
2010-04-27 13:12:03 +00:00
|
|
|
MutexRecursive();
|
|
|
|
virtual ~MutexRecursive() throw();
|
2009-10-17 18:21:30 +00:00
|
|
|
virtual bool IsRecursive() const { return true; }
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2009-10-31 19:18:29 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// ScopedLock
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Helper class for using Mutexes. Using this class provides an exception-safe (and
|
|
|
|
// generally clean) method of locking code inside a function or conditional block. The lock
|
|
|
|
// will be automatically released on any return or exit from the function.
|
2009-03-18 18:56:03 +00:00
|
|
|
//
|
2010-04-27 13:12:03 +00:00
|
|
|
// Const qualification note:
|
|
|
|
// ScopedLock takes const instances of the mutex, even though the mutex is modified
|
|
|
|
// by locking and unlocking. Two rationales:
|
|
|
|
//
|
|
|
|
// 1) when designing classes with accessors (GetString, GetValue, etc) that need mutexes,
|
|
|
|
// this class needs a const hack to allow those accessors to be const (which is typically
|
|
|
|
// *very* important).
|
|
|
|
//
|
|
|
|
// 2) The state of the Mutex is guaranteed to be unchanged when the calling function or
|
|
|
|
// scope exits, by any means. Only via manual calls to Release or Acquire does that
|
|
|
|
// change, and typically those are only used in very special circumstances of their own.
|
|
|
|
//
|
2009-08-20 14:34:48 +00:00
|
|
|
class ScopedLock
|
2009-03-16 18:32:18 +00:00
|
|
|
{
|
2009-09-21 03:33:35 +00:00
|
|
|
DeclareNoncopyableObject(ScopedLock);
|
2009-08-20 23:05:26 +00:00
|
|
|
|
2009-03-16 18:32:18 +00:00
|
|
|
protected:
|
2010-04-27 13:12:03 +00:00
|
|
|
Mutex* m_lock;
|
2010-01-22 15:22:01 +00:00
|
|
|
bool m_IsLocked;
|
2009-03-16 18:32:18 +00:00
|
|
|
|
|
|
|
public:
|
2010-04-27 13:12:03 +00:00
|
|
|
virtual ~ScopedLock() throw();
|
|
|
|
explicit ScopedLock( const Mutex* locker=NULL );
|
|
|
|
explicit ScopedLock( const Mutex& locker );
|
|
|
|
void AssignAndLock( const Mutex& locker );
|
|
|
|
void AssignAndLock( const Mutex* locker );
|
2010-05-03 13:51:46 +00:00
|
|
|
|
|
|
|
void Assign( const Mutex& locker );
|
|
|
|
void Assign( const Mutex* locker );
|
|
|
|
|
2010-04-27 13:12:03 +00:00
|
|
|
void Release();
|
|
|
|
void Acquire();
|
2009-10-21 08:57:05 +00:00
|
|
|
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
bool IsLocked() const { return m_IsLocked; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Special constructor used by ScopedTryLock
|
2010-04-27 13:12:03 +00:00
|
|
|
ScopedLock( const Mutex& locker, bool isTryLock );
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
};
|
2009-10-21 08:57:05 +00:00
|
|
|
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
class ScopedTryLock : public ScopedLock
|
|
|
|
{
|
|
|
|
public:
|
2010-04-27 13:12:03 +00:00
|
|
|
ScopedTryLock( const Mutex& locker ) : ScopedLock( locker, true ) { }
|
User Interface:
* Fixed and added better Emulation/System menu updating. Suspend/Resume is more consistent, and Reset grays itself out after being used.
* Entering plugin configurations auto-suspends the emulator.
* Changing plugins in the Configuration PAnel takes effect now without a restart.
* Added preliminary support for an ExtensibleConfirmation Dialog box (contains a sizer you can add content to, and also has an optional "[x] Do not show this again" checkbox).
Bugfixes:
* Added some mutex protection to cdvdNewDiskCB; "just in case."
* Resolved several recursion and deadlock scenarios when (very!) rapidly suspending, resuming, and resetting the emu.
Developments / Code Cleanups:
* Renamed SysCoreThread ExecutionModes: Suspend/Resume are now Opened/Closed (which more accurately reflects the fact they opena nd close the plugins, and helps avoid ambiguity with the "Paused" state).
* Added Exception::ThreadTimedOut, which is now thrown from Semaphore::Wait when recursive wxApp::Yield() calls are detected, and a deadlock occurs (basically cancels the current action which, most of the time, allows for full recovery).
* Major Threading namespace cleanups, documentations, etc.
* Removed wxScopedArray (scopedarray.h) and replaced it with a better implemeneted ScopedArray class.
* Removed toUTF8 class, which I only added a couple weeks ago because I didn't realize wxCharBuffer had an implicit typecast to (char*).
* Implemented more Source/Listener events for Pcsx2App. CoreThread events are sourced properly now, and added SettingsApplied and SettingsLoadSave Sources.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2010 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-16 03:58:29 +00:00
|
|
|
virtual ~ScopedTryLock() throw() {}
|
|
|
|
bool Failed() const { return !m_IsLocked; }
|
2009-03-16 18:32:18 +00:00
|
|
|
};
|
|
|
|
|
2009-10-31 19:18:29 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// ScopedNonblockingLock
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// A ScopedTryLock branded for use with Nonblocking mutexes. See ScopedTryLock for details.
|
|
|
|
//
|
|
|
|
class ScopedNonblockingLock
|
|
|
|
{
|
|
|
|
DeclareNoncopyableObject(ScopedNonblockingLock);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
NonblockingMutex& m_lock;
|
|
|
|
bool m_IsLocked;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ScopedNonblockingLock( NonblockingMutex& locker ) :
|
|
|
|
m_lock( locker )
|
2009-10-31 19:25:46 +00:00
|
|
|
, m_IsLocked( m_lock.TryAcquire() )
|
2009-10-31 19:18:29 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~ScopedNonblockingLock() throw()
|
|
|
|
{
|
|
|
|
if( m_IsLocked )
|
|
|
|
m_lock.Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Failed() const { return !m_IsLocked; }
|
|
|
|
};
|
2011-08-12 02:31:49 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// ScopedLockBool
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// A ScopedLock in which you specify an external bool to get updated on locks/unlocks.
|
|
|
|
// Note that the isLockedBool should only be used as an indicator for the locked status,
|
|
|
|
// and not actually depended on for thread synchronization...
|
|
|
|
|
|
|
|
struct ScopedLockBool {
|
|
|
|
ScopedLock m_lock;
|
|
|
|
volatile __aligned(4) bool& m_bool;
|
|
|
|
|
2014-08-03 18:11:22 +00:00
|
|
|
#ifdef __linux__
|
2011-08-12 18:25:21 +00:00
|
|
|
ScopedLockBool(Mutex& mutexToLock, volatile bool& isLockedBool)
|
|
|
|
#else
|
2011-08-12 02:31:49 +00:00
|
|
|
ScopedLockBool(Mutex& mutexToLock, volatile __aligned(4) bool& isLockedBool)
|
2011-08-12 18:25:21 +00:00
|
|
|
#endif
|
2011-08-12 02:31:49 +00:00
|
|
|
: m_lock(mutexToLock),
|
|
|
|
m_bool(isLockedBool) {
|
|
|
|
m_bool = m_lock.IsLocked();
|
|
|
|
}
|
|
|
|
virtual ~ScopedLockBool() throw() {
|
|
|
|
m_bool = false;
|
|
|
|
}
|
|
|
|
void Acquire() {
|
|
|
|
m_lock.Acquire();
|
|
|
|
m_bool = m_lock.IsLocked();
|
|
|
|
}
|
|
|
|
void Release() {
|
|
|
|
m_bool = false;
|
|
|
|
m_lock.Release();
|
|
|
|
}
|
|
|
|
};
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|