2010-05-07 03:20:58 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-08-18 19:47:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2010-10-18 01:40:49 +00:00
|
|
|
#include "Assertions.h"
|
|
|
|
|
2009-09-29 19:16:00 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// ScopedPtr
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template< typename T >
|
|
|
|
class ScopedPtr
|
|
|
|
{
|
|
|
|
DeclareNoncopyableObject(ScopedPtr);
|
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-09-29 19:16:00 +00:00
|
|
|
protected:
|
|
|
|
T* m_ptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef T element_type;
|
|
|
|
|
2010-05-07 03:20:58 +00:00
|
|
|
wxEXPLICIT ScopedPtr(T * ptr = NULL)
|
|
|
|
{
|
|
|
|
m_ptr = ptr;
|
|
|
|
}
|
2009-09-29 19:16:00 +00:00
|
|
|
|
2010-05-07 03:20:58 +00:00
|
|
|
~ScopedPtr() throw() { Delete(); }
|
2009-09-29 19:16:00 +00:00
|
|
|
|
|
|
|
ScopedPtr& Reassign(T * ptr = NULL)
|
|
|
|
{
|
|
|
|
if ( ptr != m_ptr )
|
|
|
|
{
|
|
|
|
Delete();
|
|
|
|
m_ptr = ptr;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2010-04-25 00:31:27 +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
|
|
|
ScopedPtr& Delete() throw()
|
2009-09-29 19:16:00 +00:00
|
|
|
{
|
|
|
|
// Thread-safe deletion: Set the pointer to NULL first, and then issue
|
|
|
|
// the deletion. This allows pending Application messages that might be
|
|
|
|
// dependent on the current object to nullify their actions.
|
|
|
|
|
|
|
|
T* deleteme = m_ptr;
|
|
|
|
m_ptr = NULL;
|
|
|
|
delete deleteme;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Removes the pointer from scoped management, but does not delete!
|
|
|
|
T *DetachPtr()
|
|
|
|
{
|
|
|
|
T *ptr = m_ptr;
|
|
|
|
m_ptr = NULL;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the managed pointer. Can return NULL as a valid result if the ScopedPtr
|
|
|
|
// has no object in management.
|
|
|
|
T* GetPtr() const
|
|
|
|
{
|
|
|
|
return m_ptr;
|
|
|
|
}
|
|
|
|
|
2011-01-10 17:48:25 +00:00
|
|
|
// Swaps two pointers between likened scoped pointer types. This method is useful for
|
|
|
|
// situations where you need to create a new object with a complex initializer that can
|
|
|
|
// throw exceptions -- and thusly should be disposed if the initialization fails. Use
|
|
|
|
// SwapPtr to assign the new object into the persistent ScopedPtr instance, and have
|
|
|
|
// the old object assigned to the local-scope ScopedPtr instance.
|
2009-09-29 19:16:00 +00:00
|
|
|
void SwapPtr(ScopedPtr& other)
|
|
|
|
{
|
|
|
|
T * const tmp = other.m_ptr;
|
|
|
|
other.m_ptr = m_ptr;
|
|
|
|
m_ptr = tmp;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-09-29 19:16:00 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// ScopedPtr Operators
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// I've decided to use the ATL's approach to pointer validity tests, opposed to
|
|
|
|
// the wx/boost approach (which uses some bizarre member method pointer crap, and can't
|
|
|
|
// allow the T* implicit casting.
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-09-29 19:16:00 +00:00
|
|
|
bool operator!() const throw()
|
|
|
|
{
|
|
|
|
return m_ptr == NULL;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-09-29 19:16:00 +00:00
|
|
|
operator T*() const
|
|
|
|
{
|
|
|
|
return m_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Equality
|
|
|
|
bool operator==(T* pT) const throw()
|
|
|
|
{
|
|
|
|
return m_ptr == pT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inequality
|
|
|
|
bool operator!=(T* pT) const throw()
|
|
|
|
{
|
|
|
|
return !operator==(pT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenient assignment operator. ScopedPtr = NULL will issue an automatic deletion
|
|
|
|
// of the managed pointer.
|
|
|
|
ScopedPtr& operator=( T* src )
|
|
|
|
{
|
|
|
|
return Reassign( src );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dereference operator, returns a handle to the managed pointer.
|
|
|
|
// Generates a debug assertion if the object is NULL!
|
|
|
|
T& operator*() const
|
|
|
|
{
|
2009-10-04 15:34:40 +00:00
|
|
|
pxAssert(m_ptr != NULL);
|
2009-09-29 19:16:00 +00:00
|
|
|
return *m_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* operator->() const
|
|
|
|
{
|
2009-10-04 15:34:40 +00:00
|
|
|
pxAssert(m_ptr != NULL);
|
2009-09-29 19:16:00 +00:00
|
|
|
return m_ptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// ScopedArray - same as ScopedPtr but uses delete[], and has operator[]
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template< typename T >
|
|
|
|
class ScopedArray
|
|
|
|
{
|
|
|
|
DeclareNoncopyableObject(ScopedArray);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T* m_array;
|
|
|
|
uint m_valid_range;
|
2010-05-07 03:20:58 +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:
|
|
|
|
typedef T element_type;
|
|
|
|
|
2010-05-07 09:55:30 +00:00
|
|
|
wxEXPLICIT ScopedArray(T * ptr = NULL)
|
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
|
|
|
{
|
2010-05-07 03:20:58 +00:00
|
|
|
m_array = ptr;
|
|
|
|
m_valid_range = 0xffffffff;
|
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
|
|
|
}
|
|
|
|
|
2010-08-03 22:18:19 +00:00
|
|
|
wxEXPLICIT ScopedArray( size_t size )
|
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
|
|
|
{
|
2010-08-03 22:18:19 +00:00
|
|
|
m_array = new T[size];
|
|
|
|
m_valid_range = size;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
~ScopedArray() throw()
|
|
|
|
{ Delete(); }
|
|
|
|
|
|
|
|
ScopedArray& Reassign(T * ptr = NULL)
|
|
|
|
{
|
|
|
|
if( ptr != m_array )
|
|
|
|
{
|
|
|
|
Delete();
|
|
|
|
m_array = ptr;
|
2010-10-18 01:40:49 +00:00
|
|
|
m_valid_range = 0xffffffff;
|
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
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2010-04-25 00:31:27 +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
|
|
|
ScopedArray& Delete() throw()
|
|
|
|
{
|
|
|
|
// Thread-safe deletion: Set the pointer to NULL first, and then issue
|
|
|
|
// the deletion. This allows pending Application messages that might be
|
|
|
|
// dependent on the current object to nullify their actions.
|
|
|
|
|
|
|
|
T* deleteme = m_array;
|
|
|
|
m_array = NULL;
|
|
|
|
delete[] deleteme;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Removes the pointer from scoped management, but does not delete!
|
|
|
|
T *DetachPtr()
|
|
|
|
{
|
|
|
|
T *ptr = m_array;
|
|
|
|
m_array = NULL;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the managed pointer. Can return NULL as a valid result if the ScopedPtr
|
|
|
|
// has no object in management.
|
|
|
|
T* GetPtr() const
|
|
|
|
{
|
|
|
|
return m_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwapPtr(ScopedArray& other)
|
|
|
|
{
|
|
|
|
T * const tmp = other.m_array;
|
|
|
|
other.m_array = m_array;
|
|
|
|
m_array = tmp;
|
|
|
|
}
|
2010-04-25 00:31:27 +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
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// ScopedPtr Operators
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// I've decided to use the ATL's approach to pointer validity tests, opposed to
|
|
|
|
// the wx/boost approach (which uses some bizarre member method pointer crap, and can't
|
|
|
|
// allow the T* implicit casting.
|
2010-04-25 00:31:27 +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 operator!() const throw()
|
|
|
|
{
|
|
|
|
return m_array == NULL;
|
|
|
|
}
|
2010-04-25 00:31:27 +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
|
|
|
// Equality
|
|
|
|
bool operator==(T* pT) const throw()
|
|
|
|
{
|
|
|
|
return m_array == pT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inequality
|
|
|
|
bool operator!=(T* pT) const throw()
|
|
|
|
{
|
|
|
|
return !operator==(pT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenient assignment operator. ScopedPtr = NULL will issue an automatic deletion
|
|
|
|
// of the managed pointer.
|
|
|
|
ScopedArray& operator=( T* src )
|
|
|
|
{
|
|
|
|
return Reassign( src );
|
|
|
|
}
|
|
|
|
|
|
|
|
T& operator[]( uint idx ) const
|
|
|
|
{
|
|
|
|
pxAssertDev( idx < m_valid_range, "Array index out of bounds on ScopedArray." );
|
|
|
|
return m_array[idx];
|
|
|
|
}
|
|
|
|
};
|
2009-09-29 19:16:00 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// pxObjPtr -- fancified version of wxScopedPtr
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// This class is a non-null scoped pointer container. What that means is that the object
|
|
|
|
// always resets itself to a valid "placebo" function rather than NULL, such that methods
|
|
|
|
// can be invoked safely without fear of NULL pointer exceptions. This system is useful
|
|
|
|
// for objects where most or all public methods can fail silently, and still allow program
|
|
|
|
// execution flow to continue.
|
|
|
|
//
|
|
|
|
// It also implements basic scoped pointer behavior: when the pxObjPtr class is deleted,
|
|
|
|
// it will automatically delete the pointer in its posession, if the pointer is valid.
|
|
|
|
//
|
|
|
|
// Notes:
|
|
|
|
// * This class intentionally does not implement the "release" API, because it doesn't
|
|
|
|
// really make sense within the context of a non-nullable pointer specification.
|
|
|
|
//
|
|
|
|
template< typename T, T& DefaultStaticInst >
|
|
|
|
class pxObjPtr
|
|
|
|
{
|
|
|
|
DeclareNoncopyableObject(pxObjPtr);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T * m_ptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef T element_type;
|
|
|
|
|
|
|
|
explicit pxObjPtr(T * ptr = &DefaultStaticInst) : m_ptr(ptr) { }
|
|
|
|
|
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
|
|
|
return m_ptr != &DefaultStaticInst;
|
|
|
|
}
|
|
|
|
|
|
|
|
~pxObjPtr()
|
|
|
|
{
|
|
|
|
if( !IsEmpty() ) delete m_ptr;
|
|
|
|
m_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// test for pointer validity: defining conversion to unspecified_bool_type
|
|
|
|
// and not more obvious bool to avoid implicit conversions to integer types
|
|
|
|
typedef T *(pxObjPtr<T,DefaultStaticInst>::*unspecified_bool_type)() const;
|
|
|
|
|
|
|
|
operator unspecified_bool_type() const
|
|
|
|
{
|
2009-09-29 22:05:21 +00:00
|
|
|
return ( !IsEmpty() ) ? &ScopedPtr<T>::get : NULL;
|
2009-09-29 19:16:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset(T * ptr = &DefaultStaticInst)
|
|
|
|
{
|
|
|
|
if ( ptr != m_ptr )
|
|
|
|
{
|
|
|
|
if( !IsEmpty() )
|
|
|
|
delete m_ptr;
|
|
|
|
m_ptr = ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
T& operator*() const
|
|
|
|
{
|
2009-10-04 15:34:40 +00:00
|
|
|
pxAssert(m_ptr != NULL);
|
2009-09-29 19:16:00 +00:00
|
|
|
return *m_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* operator->() const
|
|
|
|
{
|
2009-10-04 15:34:40 +00:00
|
|
|
pxAssert(m_ptr != NULL);
|
2009-09-29 19:16:00 +00:00
|
|
|
return m_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* get() const
|
|
|
|
{
|
2009-10-04 15:34:40 +00:00
|
|
|
pxAssert(m_ptr != NULL);
|
2009-09-29 19:16:00 +00:00
|
|
|
return m_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void swap(pxObjPtr& other)
|
|
|
|
{
|
|
|
|
// Neither pointer in either container should ever be NULL...
|
2009-10-04 15:34:40 +00:00
|
|
|
pxAssert(m_ptr != NULL);
|
|
|
|
pxAssert(other.m_ptr != NULL);
|
2009-09-29 19:16:00 +00:00
|
|
|
|
|
|
|
T * const tmp = other.m_ptr;
|
|
|
|
other.m_ptr = m_ptr;
|
|
|
|
m_ptr = tmp;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|