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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-07-03 20:48:11 +00:00
|
|
|
#include "../PrecompiledHeader.h"
|
2009-04-28 20:26:43 +00:00
|
|
|
#include "RedtapeWindows.h"
|
2009-07-03 00:49:40 +00:00
|
|
|
#include "x86emitter/tools.h"
|
|
|
|
#include "Threading.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "implement.h" // win32 pthreads implementations.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Threading
|
|
|
|
{
|
|
|
|
void CountLogicalCores( int LogicalCoresPerPhysicalCPU, int PhysicalCoresPerPhysicalCPU )
|
|
|
|
{
|
|
|
|
DWORD vProcessCPUs;
|
|
|
|
DWORD vSystemCPUs;
|
|
|
|
|
2009-07-29 14:00:00 +00:00
|
|
|
x86caps.LogicalCores = 1;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if( !GetProcessAffinityMask (GetCurrentProcess (),
|
|
|
|
&vProcessCPUs, &vSystemCPUs) ) return;
|
|
|
|
|
|
|
|
int CPUs = 0;
|
|
|
|
DWORD bit;
|
|
|
|
|
|
|
|
for (bit = 1; bit != 0; bit <<= 1)
|
|
|
|
{
|
|
|
|
if (vSystemCPUs & bit)
|
|
|
|
CPUs++;
|
|
|
|
}
|
|
|
|
|
2009-07-29 14:00:00 +00:00
|
|
|
x86caps.LogicalCores = CPUs;
|
2009-02-09 21:15:56 +00:00
|
|
|
if( LogicalCoresPerPhysicalCPU > CPUs) // for 1-socket HTT-disabled machines
|
|
|
|
LogicalCoresPerPhysicalCPU = CPUs;
|
|
|
|
|
2009-07-29 14:00:00 +00:00
|
|
|
x86caps.PhysicalCores = ( CPUs / LogicalCoresPerPhysicalCPU ) * PhysicalCoresPerPhysicalCPU;
|
|
|
|
//ptw32_smp_system = ( x86caps.LogicalCores > 1 ) ? TRUE : FALSE;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void Timeslice()
|
|
|
|
{
|
2009-02-28 20:55:53 +00:00
|
|
|
::Sleep(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline void Sleep( int ms )
|
|
|
|
{
|
2009-03-01 08:50:05 +00:00
|
|
|
::Sleep( ms );
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// For use in spin/wait loops, Acts as a hint to Intel CPUs and should, in theory
|
|
|
|
// improve performance and reduce cpu power consumption.
|
|
|
|
__forceinline void SpinWait()
|
|
|
|
{
|
|
|
|
__asm { pause };
|
|
|
|
}
|
|
|
|
}
|
2009-07-03 20:12:33 +00:00
|
|
|
|