This commit is contained in:
Aaron Robinson 2003-04-02 20:01:37 +00:00
parent 2c9076a27d
commit d3b1be57cb
4 changed files with 51 additions and 49 deletions

View File

@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}} //{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file. // Microsoft Developer Studio generated include file.
// Used by C:\Aaron\Projects\OpenXDK\cxbx\Resource\Cxbx.rc // Used by D:\OpenXDK\cxbx\Resource\Cxbx.rc
// //
#define IDI_CXBX 101 #define IDI_CXBX 101
#define IDB_SPLASH 102 #define IDB_SPLASH 102

View File

@ -83,6 +83,7 @@ INT_PTR CALLBACK DlgControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam,
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
SetClassLong(hWndDlg, GCL_HICON, (LONG)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CXBX))); SetClassLong(hWndDlg, GCL_HICON, (LONG)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CXBX)));
SetFocus(GetDlgItem(hWndDlg, IDC_SET_X));
break; break;
case WM_CLOSE: case WM_CLOSE:
EndDialog(hWndDlg, wParam); EndDialog(hWndDlg, wParam);

View File

@ -57,7 +57,6 @@ LPDIRECTINPUTDEVICE8 g_pInputDev[MAX_INPUT_DEVICES] = {0};
int g_pInputCur = 0; int g_pInputCur = 0;
xapi::XINPUT_STATE g_EmuController1; xapi::XINPUT_STATE g_EmuController1;
// ****************************************************************** // ******************************************************************
// * statics // * statics
// ****************************************************************** // ******************************************************************

View File

@ -38,10 +38,10 @@
// ****************************************************************** // ******************************************************************
Mutex::Mutex() Mutex::Mutex()
{ {
InterlockedExchange(&m_MutexLock, 0); InterlockedExchange(&m_MutexLock, 0);
InterlockedExchange(&m_OwnerProcess, 0); InterlockedExchange(&m_OwnerProcess, 0);
InterlockedExchange(&m_OwnerThread, 0); InterlockedExchange(&m_OwnerThread, 0);
InterlockedExchange(&m_LockCount, 0); InterlockedExchange(&m_LockCount, 0);
} }
// ****************************************************************** // ******************************************************************
@ -51,44 +51,45 @@ void Mutex::Lock()
{ {
while(true) while(true)
{ {
// Grab the lock, letting us look at the variables // Grab the lock, letting us look at the variables
while(InterlockedCompareExchange((LPLONG volatile)&m_MutexLock, (LONG)1, (LONG)0)) while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0))
Sleep(1); // while(InterlockedCompareExchange((LPLONG volatile)&m_MutexLock, (LONG)1, (LONG)0))
Sleep(1);
// Are we the the new owner? // Are we the the new owner?
if (!m_OwnerProcess) if (!m_OwnerProcess)
{ {
// Take ownership // Take ownership
InterlockedExchange(&m_OwnerProcess, (LONG)GetCurrentProcessId()); InterlockedExchange(&m_OwnerProcess, (LONG)GetCurrentProcessId());
InterlockedExchange(&m_OwnerThread, (LONG)GetCurrentThreadId()); InterlockedExchange(&m_OwnerThread, (LONG)GetCurrentThreadId());
InterlockedExchange(&m_LockCount, 1); InterlockedExchange(&m_LockCount, 1);
// Unlock the mutex itself // Unlock the mutex itself
InterlockedExchange(&m_MutexLock, 0); InterlockedExchange(&m_MutexLock, 0);
return; return;
} }
// If a different process owns this mutex right now, unlock // If a different process owns this mutex right now, unlock
// the mutex lock and wait. The reading need not be // the mutex lock and wait. The reading need not be
// interlocked. // interlocked.
if ((m_OwnerProcess != (LONG) GetCurrentProcessId()) || if ((m_OwnerProcess != (LONG) GetCurrentProcessId()) ||
(m_OwnerThread != (LONG) GetCurrentThreadId())) (m_OwnerThread != (LONG) GetCurrentThreadId()))
{ {
// Unlock the mutex itself // Unlock the mutex itself
InterlockedExchange(&m_MutexLock, 0); InterlockedExchange(&m_MutexLock, 0);
// Wait and try again // Wait and try again
Sleep(1); Sleep(1);
continue; continue;
} }
// The mutex was already locked, but by us. Just increment // The mutex was already locked, but by us. Just increment
// the lock count and unlock the mutex itself. // the lock count and unlock the mutex itself.
InterlockedIncrement(&m_LockCount); InterlockedIncrement(&m_LockCount);
InterlockedExchange(&m_MutexLock, 0); InterlockedExchange(&m_MutexLock, 0);
return; return;
} }
} }
@ -97,18 +98,19 @@ void Mutex::Lock()
// ****************************************************************** // ******************************************************************
void Mutex::Unlock() void Mutex::Unlock()
{ {
// Grab the lock, letting us look at the variables // Grab the lock, letting us look at the variables
while (InterlockedCompareExchange((LPLONG volatile)&m_MutexLock, (LONG)1, (LONG)0)) while(InterlockedCompareExchange((LPVOID*)&m_MutexLock, (LPVOID)1, (LPVOID)0))
Sleep(1); // while (InterlockedCompareExchange((LPLONG volatile)&m_MutexLock, (LONG)1, (LONG)0))
Sleep(1);
// Decrement the lock count // Decrement the lock count
if (!InterlockedDecrement(&m_LockCount)) if (!InterlockedDecrement(&m_LockCount))
{ {
// Mark the mutex as now unused // Mark the mutex as now unused
InterlockedExchange(&m_OwnerProcess, 0); InterlockedExchange(&m_OwnerProcess, 0);
InterlockedExchange(&m_OwnerThread, 0); InterlockedExchange(&m_OwnerThread, 0);
} }
// Unlock the mutex itself // Unlock the mutex itself
InterlockedExchange(&m_MutexLock, 0); InterlockedExchange(&m_MutexLock, 0);
} }