2009-02-09 21:15:56 +00:00
|
|
|
/* Pcsx2 - Pc Ps2 Emulator
|
2009-02-15 23:23:46 +00:00
|
|
|
* Copyright (C) 2002-2009 Pcsx2 Team
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PrecompiledHeader.h"
|
|
|
|
#include "Threading.h"
|
|
|
|
|
2009-08-25 15:38:48 +00:00
|
|
|
#include <wx/datetime.h>
|
2009-09-05 23:07:23 +00:00
|
|
|
#include <wx/thread.h>
|
|
|
|
#include <wx/app.h>
|
2009-08-25 15:38:48 +00:00
|
|
|
|
2009-08-20 23:05:26 +00:00
|
|
|
#ifdef __LINUX__
|
|
|
|
# include <signal.h> // for pthread_kill, which is in pthread.h on w32-pthreads
|
|
|
|
#endif
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
using namespace Threading;
|
|
|
|
|
|
|
|
namespace Threading
|
|
|
|
{
|
2009-09-07 21:16:12 +00:00
|
|
|
static const timespec ts_msec_200 = { 0, 200 * 1000000 };
|
|
|
|
|
2009-09-03 11:59:05 +00:00
|
|
|
static void _pt_callback_cleanup( void* handle )
|
|
|
|
{
|
|
|
|
((PersistentThread*)handle)->DoThreadCleanup();
|
|
|
|
}
|
|
|
|
|
2009-08-15 06:17:43 +00:00
|
|
|
PersistentThread::PersistentThread() :
|
2009-02-09 21:15:56 +00:00
|
|
|
m_thread()
|
2009-09-03 11:59:05 +00:00
|
|
|
, m_sem_event()
|
2009-09-07 21:16:12 +00:00
|
|
|
, m_sem_finished()
|
2009-02-09 21:15:56 +00:00
|
|
|
, m_returncode( 0 )
|
2009-09-03 11:59:05 +00:00
|
|
|
, m_detached( false )
|
2009-08-15 06:17:43 +00:00
|
|
|
, m_running( false )
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-03 11:59:05 +00:00
|
|
|
// This destructor performs basic "last chance" cleanup, which is a blocking
|
|
|
|
// join against non-detached threads. Detached threads are unhandled.
|
|
|
|
// Extending classes should always implement their own thread closure process.
|
|
|
|
// This class must not be deleted from its own thread. That would be like marrying
|
|
|
|
// your sister, and then cheating on her with your daughter.
|
2009-08-15 06:17:43 +00:00
|
|
|
PersistentThread::~PersistentThread()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-09-05 09:21:59 +00:00
|
|
|
if( !m_running ) return;
|
|
|
|
|
2009-09-03 11:59:05 +00:00
|
|
|
wxASSERT( !IsSelf() ); // not allowed from our own thread.
|
|
|
|
|
|
|
|
if( !_InterlockedExchange( &m_detached, true ) )
|
|
|
|
{
|
2009-09-07 21:16:12 +00:00
|
|
|
#if wxUSE_GUI
|
|
|
|
m_sem_finished.WaitGui( wxTimeSpan( 0, 0, 3 ) );
|
|
|
|
#else
|
|
|
|
m_sem_finished.Wait( wxTimeSpan( 0, 0, 3 ) );
|
|
|
|
#endif
|
2009-09-03 11:59:05 +00:00
|
|
|
m_running = false;
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-09-03 11:59:05 +00:00
|
|
|
// This function should not be called from the owner thread.
|
2009-08-15 06:17:43 +00:00
|
|
|
void PersistentThread::Start()
|
2009-02-17 01:38:02 +00:00
|
|
|
{
|
2009-08-31 03:47:05 +00:00
|
|
|
if( m_running ) return;
|
2009-02-17 01:38:02 +00:00
|
|
|
if( pthread_create( &m_thread, NULL, _internal_callback, this ) != 0 )
|
|
|
|
throw Exception::ThreadCreationError();
|
2009-08-15 06:17:43 +00:00
|
|
|
|
|
|
|
m_running = true;
|
|
|
|
}
|
|
|
|
|
2009-09-03 11:59:05 +00:00
|
|
|
// This function should not be called from the owner thread.
|
|
|
|
void PersistentThread::Detach()
|
|
|
|
{
|
2009-09-05 09:21:59 +00:00
|
|
|
if( !m_running ) return;
|
2009-09-03 11:59:05 +00:00
|
|
|
if( _InterlockedExchange( &m_detached, true ) ) return;
|
2009-09-05 09:21:59 +00:00
|
|
|
|
|
|
|
wxASSERT( !IsSelf() ); // not allowed from our own thread.
|
2009-09-03 11:59:05 +00:00
|
|
|
pthread_detach( m_thread );
|
|
|
|
}
|
|
|
|
|
2009-08-15 06:17:43 +00:00
|
|
|
// Remarks:
|
|
|
|
// Provision of non-blocking Cancel() is probably academic, since destroying a PersistentThread
|
|
|
|
// object performs a blocking Cancel regardless of if you explicitly do a non-blocking Cancel()
|
|
|
|
// prior, since the ExecuteTask() method requires a valid object state. If you really need
|
|
|
|
// fire-and-forget behavior on threads, use pthreads directly for now.
|
2009-09-03 11:59:05 +00:00
|
|
|
//
|
|
|
|
// This function should not be called from the owner thread.
|
2009-08-15 06:17:43 +00:00
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// isBlocking - indicates if the Cancel action should block for thread completion or not.
|
|
|
|
//
|
|
|
|
void PersistentThread::Cancel( bool isBlocking )
|
|
|
|
{
|
2009-09-05 12:02:07 +00:00
|
|
|
if( !m_running ) return;
|
|
|
|
|
2009-09-03 11:59:05 +00:00
|
|
|
if( _InterlockedExchange( &m_detached, true ) )
|
|
|
|
{
|
|
|
|
if( m_running )
|
|
|
|
Console::Notice( "Threading Warning: Attempted to cancel detached thread; Ignoring..." );
|
|
|
|
return;
|
|
|
|
}
|
2009-08-15 06:17:43 +00:00
|
|
|
|
2009-09-05 09:21:59 +00:00
|
|
|
wxASSERT( !IsSelf() );
|
2009-08-15 06:17:43 +00:00
|
|
|
pthread_cancel( m_thread );
|
2009-09-03 11:59:05 +00:00
|
|
|
|
2009-08-15 06:17:43 +00:00
|
|
|
if( isBlocking )
|
2009-09-07 21:16:12 +00:00
|
|
|
{
|
|
|
|
#if wxUSE_GUI
|
|
|
|
m_sem_finished.WaitGui( wxTimeSpan( 0, 0, 3 ) );
|
|
|
|
#else
|
|
|
|
m_sem_finished.Wait( wxTimeSpan( 0, 0, 3 ) );
|
|
|
|
#endif
|
|
|
|
}
|
2009-08-15 06:17:43 +00:00
|
|
|
else
|
|
|
|
pthread_detach( m_thread );
|
2009-09-03 11:59:05 +00:00
|
|
|
|
|
|
|
m_running = false;
|
2009-02-17 01:38:02 +00:00
|
|
|
}
|
|
|
|
|
2009-08-15 06:17:43 +00:00
|
|
|
// Blocks execution of the calling thread until this thread completes its task. The
|
|
|
|
// caller should make sure to signal the thread to exit, or else blocking may deadlock the
|
|
|
|
// calling thread. Classes which extend PersistentThread should override this method
|
|
|
|
// and signal any necessary thread exit variables prior to blocking.
|
|
|
|
//
|
|
|
|
// Returns the return code of the thread.
|
|
|
|
// This method is roughly the equivalent of pthread_join().
|
|
|
|
//
|
|
|
|
sptr PersistentThread::Block()
|
|
|
|
{
|
2009-09-03 11:59:05 +00:00
|
|
|
if( _InterlockedExchange( &m_detached, true ) )
|
|
|
|
{
|
|
|
|
// already detached: if we're still running then its an invalid operation
|
|
|
|
if( m_running )
|
|
|
|
throw Exception::InvalidOperation( "Blocking on detached threads requires manual semaphore implementation." );
|
|
|
|
|
|
|
|
return m_returncode;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-05 09:21:59 +00:00
|
|
|
DevAssert( !IsSelf(), "Thread deadlock detected; Block() should never be called by the owner thread." );
|
2009-09-07 21:16:12 +00:00
|
|
|
|
|
|
|
#if wxUSE_GUI
|
|
|
|
m_sem_finished.WaitGui( wxTimeSpan( 0, 0, 3 ) );
|
|
|
|
#else
|
|
|
|
m_sem_finished.Wait( wxTimeSpan( 0, 0, 3 ) );
|
|
|
|
#endif
|
2009-09-03 11:59:05 +00:00
|
|
|
return m_returncode;
|
|
|
|
}
|
2009-08-15 06:17:43 +00:00
|
|
|
}
|
2009-09-05 09:21:59 +00:00
|
|
|
|
2009-08-31 03:47:05 +00:00
|
|
|
bool PersistentThread::IsSelf() const
|
|
|
|
{
|
|
|
|
return pthread_self() == m_thread;
|
|
|
|
}
|
2009-08-20 23:05:26 +00:00
|
|
|
|
2009-08-15 06:17:43 +00:00
|
|
|
bool PersistentThread::IsRunning() const
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-09-03 11:59:05 +00:00
|
|
|
if( !!m_detached )
|
|
|
|
return !!m_running;
|
|
|
|
else
|
|
|
|
return ( ESRCH != pthread_kill( m_thread, 0 ) );
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-08-15 06:17:43 +00:00
|
|
|
// Exceptions:
|
|
|
|
// InvalidOperation - thrown if the thread is still running or has never been started.
|
|
|
|
//
|
|
|
|
sptr PersistentThread::GetReturnCode() const
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-08-15 06:17:43 +00:00
|
|
|
if( IsRunning() )
|
|
|
|
throw Exception::InvalidOperation( "Thread.GetReturnCode : thread is still running." );
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
return m_returncode;
|
|
|
|
}
|
2009-08-20 23:05:26 +00:00
|
|
|
|
2009-09-03 11:59:05 +00:00
|
|
|
// invoked when canceling or exiting the thread.
|
|
|
|
void PersistentThread::DoThreadCleanup()
|
|
|
|
{
|
|
|
|
wxASSERT( IsSelf() ); // only allowed from our own thread, thanks.
|
|
|
|
_InterlockedExchange( &m_running, false );
|
|
|
|
}
|
|
|
|
|
2009-08-15 06:17:43 +00:00
|
|
|
void* PersistentThread::_internal_callback( void* itsme )
|
|
|
|
{
|
|
|
|
jASSUME( itsme != NULL );
|
|
|
|
PersistentThread& owner = *((PersistentThread*)itsme);
|
2009-09-03 11:59:05 +00:00
|
|
|
|
|
|
|
pthread_cleanup_push( _pt_callback_cleanup, itsme );
|
2009-08-15 06:17:43 +00:00
|
|
|
owner.m_returncode = owner.ExecuteTask();
|
2009-09-03 11:59:05 +00:00
|
|
|
pthread_cleanup_pop( true );
|
|
|
|
|
2009-08-15 06:17:43 +00:00
|
|
|
return (void*)owner.m_returncode;
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 02:08:37 +00:00
|
|
|
// pthread Cond is an evil api that is not suited for Pcsx2 needs.
|
|
|
|
// Let's not use it. (Air)
|
|
|
|
#if 0
|
2009-07-03 20:12:33 +00:00
|
|
|
WaitEvent::WaitEvent()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
2009-07-03 20:12:33 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
err = pthread_cond_init(&cond, NULL);
|
|
|
|
err = pthread_mutex_init(&mutex, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitEvent::~WaitEvent()
|
|
|
|
{
|
|
|
|
pthread_cond_destroy( &cond );
|
|
|
|
pthread_mutex_destroy( &mutex );
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitEvent::Set()
|
|
|
|
{
|
|
|
|
pthread_mutex_lock( &mutex );
|
|
|
|
pthread_cond_signal( &cond );
|
|
|
|
pthread_mutex_unlock( &mutex );
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitEvent::Wait()
|
|
|
|
{
|
|
|
|
pthread_mutex_lock( &mutex );
|
|
|
|
pthread_cond_wait( &cond, &mutex );
|
|
|
|
pthread_mutex_unlock( &mutex );
|
|
|
|
}
|
2009-02-24 02:08:37 +00:00
|
|
|
#endif
|
2009-02-28 20:55:53 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
Semaphore::Semaphore()
|
|
|
|
{
|
|
|
|
sem_init( &sema, false, 0 );
|
|
|
|
}
|
2009-07-03 20:12:33 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
Semaphore::~Semaphore()
|
|
|
|
{
|
|
|
|
sem_destroy( &sema );
|
|
|
|
}
|
|
|
|
|
2009-02-28 20:55:53 +00:00
|
|
|
void Semaphore::Reset()
|
|
|
|
{
|
|
|
|
sem_destroy( &sema );
|
|
|
|
sem_init( &sema, false, 0 );
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
void Semaphore::Post()
|
|
|
|
{
|
|
|
|
sem_post( &sema );
|
|
|
|
}
|
|
|
|
|
2009-08-25 15:38:48 +00:00
|
|
|
// Valid on Win32 builds only!! Attempts to use it on Linux will result in unresolved
|
|
|
|
// external linker errors.
|
|
|
|
#if defined(_MSC_VER)
|
2009-02-09 21:15:56 +00:00
|
|
|
void Semaphore::Post( int multiple )
|
|
|
|
{
|
|
|
|
sem_post_multiple( &sema, multiple );
|
|
|
|
}
|
2009-08-25 15:38:48 +00:00
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-09-05 23:07:23 +00:00
|
|
|
#if wxUSE_GUI
|
|
|
|
// This is a wxApp-safe implementation of Wait, which makes sure and executes the App's
|
|
|
|
// pending messages *if* the Wait is performed on the Main/GUI thread. If the Wait is
|
|
|
|
// called from another thread, no message pumping is performed.
|
|
|
|
void Semaphore::WaitGui()
|
|
|
|
{
|
|
|
|
if( !wxThread::IsMain() || (wxTheApp == NULL) )
|
|
|
|
Wait();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// In order to avoid deadlock we need to make sure we cut some time
|
|
|
|
// to handle messages. I choose 200ms:
|
|
|
|
|
|
|
|
do {
|
|
|
|
wxTheApp->ProcessPendingEvents();
|
2009-09-07 21:16:12 +00:00
|
|
|
} while( sem_timedwait( &sema, &ts_msec_200 ) == ETIMEDOUT );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Semaphore::WaitGui( const wxTimeSpan& timeout )
|
|
|
|
{
|
|
|
|
if( !wxThread::IsMain() || (wxTheApp == NULL) )
|
|
|
|
{
|
|
|
|
return Wait( timeout );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxTimeSpan countdown( (timeout) );
|
|
|
|
|
|
|
|
// In order to avoid deadlock we need to make sure we cut some time
|
|
|
|
// to handle messages. I choose 200ms:
|
|
|
|
|
|
|
|
static const wxTimeSpan pass( 0, 0, 0, 200 );
|
|
|
|
do {
|
|
|
|
wxTheApp->ProcessPendingEvents();
|
|
|
|
if( sem_timedwait( &sema, &ts_msec_200 ) != ETIMEDOUT )
|
|
|
|
break;
|
|
|
|
countdown -= pass;
|
|
|
|
} while( countdown.GetMilliseconds() > 0 );
|
|
|
|
|
|
|
|
return countdown.GetMilliseconds() > 0;
|
2009-09-05 23:07:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
void Semaphore::Wait()
|
|
|
|
{
|
|
|
|
sem_wait( &sema );
|
|
|
|
}
|
|
|
|
|
2009-09-07 21:16:12 +00:00
|
|
|
bool Semaphore::Wait( const wxTimeSpan& timeout )
|
2009-08-25 15:38:48 +00:00
|
|
|
{
|
|
|
|
const timespec fail = { timeout.GetSeconds().GetLo(), 0 };
|
2009-09-07 21:16:12 +00:00
|
|
|
return sem_timedwait( &sema, &fail ) != ETIMEDOUT;
|
2009-08-25 15:38:48 +00:00
|
|
|
}
|
|
|
|
|
2009-08-15 06:17:43 +00:00
|
|
|
// Performs an uncancellable wait on a semaphore; restoring the thread's previous cancel state
|
|
|
|
// after the wait has completed. Useful for situations where the semaphore itself is stored on
|
|
|
|
// the stack and passed to another thread via GUI message or such, avoiding complications where
|
2009-08-25 15:38:48 +00:00
|
|
|
// the thread might be canceled and the stack value becomes invalid.
|
2009-08-15 06:17:43 +00:00
|
|
|
//
|
|
|
|
// Performance note: this function has quite a bit more overhead compared to Semaphore::Wait(), so
|
|
|
|
// consider manually specifying the thread as uncancellable and using Wait() instead if you need
|
|
|
|
// to do a lot of no-cancel waits in a tight loop worker thread, for example.
|
|
|
|
void Semaphore::WaitNoCancel()
|
|
|
|
{
|
|
|
|
int oldstate;
|
|
|
|
pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &oldstate );
|
|
|
|
Wait();
|
|
|
|
pthread_setcancelstate( oldstate, NULL );
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
int Semaphore::Count()
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
sem_getvalue( &sema, &retval );
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
MutexLock::MutexLock()
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
err = pthread_mutex_init( &mutex, NULL );
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:05:48 +00:00
|
|
|
MutexLock::MutexLock( bool isRecursive )
|
|
|
|
{
|
|
|
|
if( isRecursive )
|
|
|
|
{
|
2009-08-20 23:05:26 +00:00
|
|
|
pthread_mutexattr_t mutexAttribute;
|
2009-07-03 06:05:48 +00:00
|
|
|
int status = pthread_mutexattr_init( &mutexAttribute );
|
2009-08-20 23:05:26 +00:00
|
|
|
if (status != 0) { /* ... */ }
|
|
|
|
status = pthread_mutexattr_settype( &mutexAttribute, PTHREAD_MUTEX_RECURSIVE);
|
|
|
|
if (status != 0) { /* ... */}
|
2009-07-03 06:05:48 +00:00
|
|
|
|
|
|
|
int err = 0;
|
|
|
|
err = pthread_mutex_init( &mutex, &mutexAttribute );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
err = pthread_mutex_init( &mutex, NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
MutexLock::~MutexLock()
|
|
|
|
{
|
|
|
|
pthread_mutex_destroy( &mutex );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutexLock::Lock()
|
|
|
|
{
|
|
|
|
pthread_mutex_lock( &mutex );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MutexLock::Unlock()
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock( &mutex );
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// define some overloads for InterlockedExchanges
|
|
|
|
// for commonly used types, like u32 and s32.
|
2009-07-03 20:12:33 +00:00
|
|
|
|
|
|
|
__forceinline long pcsx2_InterlockedExchange( volatile long* target, long srcval )
|
|
|
|
{
|
|
|
|
return _InterlockedExchange( target, srcval );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline long pcsx2_InterlockedCompareExchange( volatile long* target, long srcval, long comp )
|
|
|
|
{
|
|
|
|
// Use the pthreads-win32 implementation...
|
|
|
|
return _InterlockedCompareExchange( target, srcval, comp );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline long pcsx2_InterlockedExchangeAdd( volatile long* target, long srcval )
|
|
|
|
{
|
|
|
|
return _InterlockedExchangeAdd( target, srcval );
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
__forceinline void AtomicExchange( volatile u32& Target, u32 value )
|
|
|
|
{
|
|
|
|
pcsx2_InterlockedExchange( (volatile long*)&Target, value );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void AtomicExchangeAdd( volatile u32& Target, u32 value )
|
|
|
|
{
|
|
|
|
pcsx2_InterlockedExchangeAdd( (volatile long*)&Target, value );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void AtomicIncrement( volatile u32& Target )
|
|
|
|
{
|
|
|
|
pcsx2_InterlockedExchangeAdd( (volatile long*)&Target, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void AtomicDecrement( volatile u32& Target )
|
|
|
|
{
|
|
|
|
pcsx2_InterlockedExchangeAdd( (volatile long*)&Target, -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void AtomicExchange( volatile s32& Target, s32 value )
|
|
|
|
{
|
|
|
|
pcsx2_InterlockedExchange( (volatile long*)&Target, value );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void AtomicExchangeAdd( s32& Target, u32 value )
|
|
|
|
{
|
|
|
|
pcsx2_InterlockedExchangeAdd( (volatile long*)&Target, value );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void AtomicIncrement( volatile s32& Target )
|
|
|
|
{
|
|
|
|
pcsx2_InterlockedExchangeAdd( (volatile long*)&Target, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void AtomicDecrement( volatile s32& Target )
|
|
|
|
{
|
|
|
|
pcsx2_InterlockedExchangeAdd( (volatile long*)&Target, -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void _AtomicExchangePointer( const void ** target, const void* value )
|
|
|
|
{
|
|
|
|
pcsx2_InterlockedExchange( (volatile long*)target, (long)value );
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void _AtomicCompareExchangePointer( const void ** target, const void* value, const void* comparand )
|
|
|
|
{
|
|
|
|
pcsx2_InterlockedCompareExchange( (volatile long*)target, (long)value, (long)comparand );
|
|
|
|
}
|
|
|
|
|
2009-07-03 20:12:33 +00:00
|
|
|
}
|