本文整理汇总了C++中SetThreadAffinityMask函数的典型用法代码示例。如果您正苦于以下问题:C++ SetThreadAffinityMask函数的具体用法?C++ SetThreadAffinityMask怎么用?C++ SetThreadAffinityMask使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetThreadAffinityMask函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defined
void PixelPipeline::worker_main(int core)
{
#if defined(WIN32) && defined(PROFILE_PIPELINE)
SetThreadIdealProcessor(GetCurrentThread(), core);
SetThreadAffinityMask(GetCurrentThread(), 1 << core);
unsigned __int64 ticks_waiting = 0;
unsigned __int64 ticks_working = 0;
#endif
PixelThreadContext context(core, active_cores);
while (true)
{
#if defined(WIN32) && defined(PROFILE_PIPELINE)
unsigned __int64 wait_start_time = __rdtsc();
#endif
int wakeup_reason = Event::wait(event_more_commands[core], event_stop);
if (wakeup_reason != 0)
break;
event_more_commands[core].reset();
#if defined(WIN32) && defined(PROFILE_PIPELINE)
unsigned __int64 wait_end_time = __rdtsc();
ticks_waiting += wait_end_time-wait_start_time;
#endif
process_commands(&context);
#if defined(WIN32) && defined(PROFILE_PIPELINE)
unsigned __int64 commands_end_time = __rdtsc();
ticks_working += commands_end_time-wait_end_time;
#endif
}
#if defined(WIN32) && defined(PROFILE_PIPELINE)
MessageBoxA(
0,
cl_format("Pipeline core %1 spent %2 percent of its time waiting for commands",
core,
(int)(ticks_waiting*100/(ticks_working+ticks_waiting))).c_str(),
"DEBUG", MB_OK);
#endif
}
示例2: setAffinity
/*! set the affinity of a given thread */
void setAffinity(HANDLE thread, ssize_t affinity)
{
#if (_WIN32_WINNT >= 0x0601) // FIXME: use getProcAddress to activate this feature only if supported by Windows
int groups = GetActiveProcessorGroupCount();
int totalProcessors = 0, group = 0, number = 0;
for (int i = 0; i<groups; i++) {
int processors = GetActiveProcessorCount(i);
if (totalProcessors + processors > affinity) {
group = i;
number = (int)affinity - totalProcessors;
break;
}
totalProcessors += processors;
}
GROUP_AFFINITY groupAffinity;
groupAffinity.Group = (WORD)group;
groupAffinity.Mask = (KAFFINITY)(uint64(1) << number);
groupAffinity.Reserved[0] = 0;
groupAffinity.Reserved[1] = 0;
groupAffinity.Reserved[2] = 0;
if (!SetThreadGroupAffinity(thread, &groupAffinity, NULL))
THROW_RUNTIME_ERROR("cannot set thread group affinity");
PROCESSOR_NUMBER processorNumber;
processorNumber.Group = group;
processorNumber.Number = number;
processorNumber.Reserved = 0;
if (!SetThreadIdealProcessorEx(thread, &processorNumber, NULL))
THROW_RUNTIME_ERROR("cannot set ideal processor");
#else
if (!SetThreadAffinityMask(thread, DWORD_PTR(uint64(1) << affinity)))
THROW_RUNTIME_ERROR("cannot set thread affinity mask");
if (SetThreadIdealProcessor(thread, (DWORD)affinity) == (DWORD)-1)
THROW_RUNTIME_ERROR("cannot set ideal processor");
#endif
}
示例3: setAffinity
/*! set the affinity of a given thread */
void setAffinity(HANDLE thread, ssize_t affinity)
{
#if (_WIN32_WINNT >= 0x0601)
int groups = GetActiveProcessorGroupCount();
int totalProcessors = 0, group = 0, number = 0;
for (int i = 0; i<groups; i++) {
int processors = GetActiveProcessorCount(i);
if (totalProcessors + processors > affinity) {
group = i;
number = (int)affinity - totalProcessors;
break;
}
totalProcessors += processors;
}
GROUP_AFFINITY groupAffinity;
groupAffinity.Group = (WORD)group;
groupAffinity.Mask = (KAFFINITY)(uint64(1) << number);
groupAffinity.Reserved[0] = 0;
groupAffinity.Reserved[1] = 0;
groupAffinity.Reserved[2] = 0;
if (!SetThreadGroupAffinity(thread, &groupAffinity, NULL))
throw std::runtime_error("cannot set thread group affinity");
PROCESSOR_NUMBER processorNumber;
processorNumber.Group = group;
processorNumber.Number = number;
processorNumber.Reserved = 0;
if (!SetThreadIdealProcessorEx(thread, &processorNumber, NULL))
throw std::runtime_error("cannot set thread ideal processor");
#else
if (!SetThreadAffinityMask(thread, DWORD_PTR(uint64(1) << affinity)))
throw std::runtime_error("cannot set thread affinity mask");
if (SetThreadIdealProcessor(thread, (DWORD)affinity) == (DWORD)-1)
throw std::runtime_error("cannot set thread ideal processor");
#endif
}
示例4: main_frame
Application::Application(void): main_frame(),
ec(),
ecm(),
fc(),
evc(),
evcm(),
fcm(),
navigator_manager(),
graphic_factory(),
layer_tree(),
plugin_map(),
three_dimension_camera_controller(NULL),
two_dimension_camera_controller(NULL),
dc(NULL),
plugin_running(false),
srs()
{
//for being able to load all type of images
wxInitAllImageHandlers();
#ifdef WIN32
//This is to activate memory-leaks detection
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
wmsInitialize();
application_time = ApplicationTime::GetInstance();
application_time->Off();
cpw::IdGenerator::SetNamespace(GetMACaddress());
#ifdef WIN32
SetThreadAffinityMask(GetCurrentThread(), 0);
#endif
}
示例5: vm_affinity_thread_get
vm_status vm_affinity_thread_get(vm_thread *pthr, vm_affinity_mask *mptr)
{
DWORD processmask = 0;
if(!mptr)
return VM_NULL_PTR;
if(mptr[0].msklen)
{
/* only one way to obtain thread affinity mask - set it again */
if (pthr[0].preset_affinity_mask)
{
mptr[0].mskbits[0] = (unsigned long)SetThreadAffinityMask(pthr[0].handle, pthr[0].preset_affinity_mask);
return VM_OK;
}
else
{
if(GetProcessAffinityMask(pthr[0].handle, (PDWORD_PTR)&processmask, (PDWORD_PTR)mptr[0].mskbits))
return VM_OK;
}
}
return VM_OPERATION_FAILED;
}
示例6: Sys_StartAsyncThread
/*
==============
Sys_StartAsyncThread
Start the thread that will call idCommon::Async()
==============
*/
void Sys_StartAsyncThread(void)
{
// create an auto-reset event that happens 60 times a second
hTimer = CreateWaitableTimer(NULL, false, NULL);
if (!hTimer) {
common->Error("idPacketServer::Spawn: CreateWaitableTimer failed");
}
LARGE_INTEGER t;
t.HighPart = t.LowPart = 0;
SetWaitableTimer(hTimer, &t, USERCMD_MSEC, NULL, NULL, TRUE);
Sys_CreateThread((xthread_t)Sys_AsyncThread, NULL, THREAD_ABOVE_NORMAL, threadInfo, "Async", g_threads, &g_thread_count);
#ifdef SET_THREAD_AFFINITY
// give the async thread an affinity for the second cpu
SetThreadAffinityMask((HANDLE)threadInfo.threadHandle, 2);
#endif
if (!threadInfo.threadHandle) {
common->Error("Sys_StartAsyncThread: failed");
}
}
示例7: LunaDLLInit
// We don't call this directly from DLL_PROCESS_ATTACH because if we do things
// can break when we're loaded via LoadLibrary
// Instead this is called by LunaDLLInitHook, which is set up by
// SetupLunaDLLInitHook that runs from DLL_PROCESS_ATTACH
void LunaDLLInit()
{
InitGlobals();
#if PATCHIT
TrySkipPatch();
#endif // PATCHIT
// Test OpenGL support
if (!gStartupSettings.noGL && LunaDLLTestGLFeatures()) {
g_GLEngine.Enable();
} else {
g_GLEngine.Disable();
}
// Set processor affinity for the main thread. Switching cores is bad for stable frame rate
DWORD curProcessor = GetCurrentProcessorNumberXP();
SetThreadAffinityMask(GetCurrentThread(), 1 << curProcessor);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
// Initialize GDI+ so we can make use of it
ULONG_PTR m_gdiplusToken; // class member
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
}
示例8: CPU_SET
bool CAdvThread::setAffinity()
{
#ifdef Q_OS_LINUX
if(threadHandle != 0)
{
int j;
for (j = 0; j < coreQuantity; j++)
if(affinityData.coreMask & (1<<j))
CPU_SET(j, &cpuset);
pthread_setaffinity_np(threadHandle, sizeof(cpu_set_t), &cpuset);
}
#else
if(threadHandle != 0)
{
DWORD_PTR res = SetThreadAffinityMask(threadHandle, affinityData.coreMask);
if (0 == res)
{
// failure
}
}
#endif
affinityData.coreChanged = 0;
}
示例9: defined
RakNetTimeNS RakNet::GetTimeNS( void )
{
#if defined(_PS3)
uint64_t curTime;
if ( initialized == false)
{
ticksPerSecond = _PS3_GetTicksPerSecond();
// Use the function to get elapsed ticks, this is a macro.
_PS3_GetElapsedTicks(curTime);
uint64_t quotient, remainder;
quotient=(curTime / ticksPerSecond);
remainder=(curTime % ticksPerSecond);
initialTime = (RakNetTimeNS) quotient*(RakNetTimeNS)1000000 + (remainder*(RakNetTimeNS)1000000 / ticksPerSecond);
initialized = true;
}
#elif defined(_WIN32)
// Win32
if ( initialized == false)
{
initialized = true;
#if !defined(_WIN32_WCE)
// Save the current process
HANDLE mProc = GetCurrentProcess();
// Get the current Affinity
#if _MSC_VER >= 1400 && defined (_M_X64)
GetProcessAffinityMask(mProc, (PDWORD_PTR)&mProcMask, (PDWORD_PTR)&mSysMask);
#else
GetProcessAffinityMask(mProc, &mProcMask, &mSysMask);
#endif
mThread = GetCurrentThread();
#endif // !defined(_WIN32_WCE)
QueryPerformanceFrequency( &yo );
}
// 01/12/08 - According to the docs "The frequency cannot change while the system is running." so this shouldn't be necessary
/*
if (++queryCount==200)
{
// Set affinity to the first core
SetThreadAffinityMask(mThread, 1);
QueryPerformanceFrequency( &yo );
// Reset affinity
SetThreadAffinityMask(mThread, mProcMask);
queryCount=0;
}
*/
#elif (defined(__GNUC__) || defined(__GCCXML__))
if ( initialized == false)
{
gettimeofday( &tp, 0 );
initialized=true;
// I do this because otherwise RakNetTime in milliseconds won't work as it will underflow when dividing by 1000 to do the conversion
initialTime = ( tp.tv_sec ) * (RakNetTimeNS) 1000000 + ( tp.tv_usec );
}
#endif
#if defined(_PS3)
// Use the function to get elapsed ticks, this is a macro.
_PS3_GetElapsedTicks(curTime);
uint64_t quotient, remainder;
quotient=(curTime / ticksPerSecond);
remainder=(curTime % ticksPerSecond);
curTime = (RakNetTimeNS) quotient*(RakNetTimeNS)1000000 + (remainder*(RakNetTimeNS)1000000 / ticksPerSecond);
// Subtract from initialTime so the millisecond conversion does not underflow
return curTime - initialTime;
#elif defined(_WIN32)
RakNetTimeNS curTime;
static RakNetTimeNS lastQueryVal=(RakNetTimeNS)0;
// static unsigned long lastTickCountVal = GetTickCount();
LARGE_INTEGER PerfVal;
#if !defined(_WIN32_WCE)
// Set affinity to the first core
SetThreadAffinityMask(mThread, 1);
#endif // !defined(_WIN32_WCE)
// Docs: On a multiprocessor computer, it should not matter which processor is called.
// However, you can get different results on different processors due to bugs in the basic input/output system (BIOS) or the hardware abstraction layer (HAL). To specify processor affinity for a thread, use the SetThreadAffinityMask function.
// Query the timer
QueryPerformanceCounter( &PerfVal );
#if !defined(_WIN32_WCE)
// Reset affinity
SetThreadAffinityMask(mThread, mProcMask);
#endif // !defined(_WIN32_WCE)
__int64 quotient, remainder;
quotient=((PerfVal.QuadPart) / yo.QuadPart);
remainder=((PerfVal.QuadPart) % yo.QuadPart);
curTime = (RakNetTimeNS) quotient*(RakNetTimeNS)1000000 + (remainder*(RakNetTimeNS)1000000 / yo.QuadPart);
//.........这里部分代码省略.........
示例10: printf
void b3Win32ThreadSupport::startThreads(const Win32ThreadConstructionInfo& threadConstructionInfo)
{
static int uniqueId = 0;
uniqueId++;
m_activeThreadStatus.resize(threadConstructionInfo.m_numThreads);
m_completeHandles.resize(threadConstructionInfo.m_numThreads);
m_maxNumTasks = threadConstructionInfo.m_numThreads;
for (int i=0;i<threadConstructionInfo.m_numThreads;i++)
{
printf("starting thread %d\n",i);
b3ThreadStatus& threadStatus = m_activeThreadStatus[i];
LPSECURITY_ATTRIBUTES lpThreadAttributes=NULL;
SIZE_T dwStackSize=threadConstructionInfo.m_threadStackSize;
LPTHREAD_START_ROUTINE lpStartAddress=&Thread_no_1;
LPVOID lpParameter=&threadStatus;
DWORD dwCreationFlags=0;
LPDWORD lpThreadId=0;
threadStatus.m_userPtr=0;
sprintf(threadStatus.m_eventStartHandleName,"es%.8s%d%d",threadConstructionInfo.m_uniqueName,uniqueId,i);
threadStatus.m_eventStartHandle = CreateEventA (0,false,false,threadStatus.m_eventStartHandleName);
sprintf(threadStatus.m_eventCompletetHandleName,"ec%.8s%d%d",threadConstructionInfo.m_uniqueName,uniqueId,i);
threadStatus.m_eventCompletetHandle = CreateEventA (0,false,false,threadStatus.m_eventCompletetHandleName);
m_completeHandles[i] = threadStatus.m_eventCompletetHandle;
HANDLE handle = CreateThread(lpThreadAttributes,dwStackSize,lpStartAddress,lpParameter, dwCreationFlags,lpThreadId);
switch(threadConstructionInfo.m_priority)
{
case 0:
{
SetThreadPriority(handle,THREAD_PRIORITY_HIGHEST);
break;
}
case 1:
{
SetThreadPriority(handle,THREAD_PRIORITY_TIME_CRITICAL);
break;
}
case 2:
{
SetThreadPriority(handle,THREAD_PRIORITY_BELOW_NORMAL);
break;
}
default:
{
}
}
DWORD mask = 1;
mask = 1<<mask;
SetThreadAffinityMask(handle, mask);
threadStatus.m_taskId = i;
threadStatus.m_commandId = 0;
threadStatus.m_status = 0;
threadStatus.m_threadHandle = handle;
threadStatus.m_lsMemory = threadConstructionInfo.m_lsMemoryFunc();
threadStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc;
printf("started %s thread %d with threadHandle %p\n",threadConstructionInfo.m_uniqueName,i,handle);
}
}
示例11: wthread_set_affinity_mask
int wthread_set_affinity_mask( wthread_t h,
CPU_AFFINITY_SET* dwThreadAffinityMask)
{
return (int) SetThreadAffinityMask( ((threadContext*) h)->mThread,
(DWORD_PTR) dwThreadAffinityMask );
}
示例12: SetThreadAffinityMask
void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
{
SetThreadAffinityMask (GetCurrentThread(), affinityMask);
}
示例13: jsInit
void jsInit()
{
#ifdef DEBUG_OUTPUT
g_pDebugLog = fopen("JS_DEBUG.log", "w");
#endif
//find number of cores
SYSTEM_INFO sysInfo = { 0 };
GetSystemInfo(&sysInfo);
g_numProcessors = sysInfo.dwNumberOfProcessors;
//spawn fibers
for (int i = 0; i < NUM_FIBERS; ++i)
{
g_fibers[i].fiber = CreateFiber(FIBER_STACK_SIZE, fiberRoutine, g_fibers + i);
g_fibers[i].pNextInWaitList = NULL;
g_fibers[i].status = UNUSED;
g_pFiberPool[NUM_FIBERS - 1 - i] = g_fibers + i;
}
//init waiting fibers
memset(g_waitingFibers, 0, sizeof(g_waitingFibers));
g_waitingFiberHead = 0;
g_waitListTail.pFiber = NULL;
g_waitListTail.pNextWaitingFiber = NULL;
g_waitListTail.time = 0;
//get performance frequency
QueryPerformanceFrequency((LARGE_INTEGER*)&g_performanceFrequency);
//init jobs
for (int i = 2; i < MAX_JOBS; ++i)
{
g_jobs[i - 1].pNextJob = g_jobs + i;
}
g_pFreeJob = g_jobs + 1;
g_pJobQueueHead = g_jobs;
g_dummyJob.threadId = 0x0;
g_dummyJob.pNextJob = g_pJobQueueHead;
g_dummyJob.pName = "__dummy";
//spawn threads
g_threadData = TlsAlloc();
for (int i = 0; i < g_numProcessors; ++i)
{
//create thread
if (i == 0)
{
g_threads[0].handle = GetCurrentThread();
}
else
{
g_threads[i].handle = CreateThread(NULL, 0, threadStart, g_threads + i, 0, NULL);
}
g_threads[i].id = 0x1 << i;
g_threads[i].ppJobQueueTail = &(g_dummyJob.pNextJob);
//lock thread to specific cpu
SetThreadAffinityMask(g_threads[i].handle, 1 << i);
}
TlsSetValue(g_threadData, g_threads + 0);
initCounterAllocator();
#ifdef DEBUG_OUTPUT
fprintf(g_pDebugLog, "%lld \t jobsystem started\n", time(NULL));
#endif
}
示例14: GetCPUThreadCount
bool MScheduler::Init( uint32 numThreads )
{
static const uint32 cProcessors = GetCPUThreadCount();
AX_ASSERT( cProcessors > 0 );
const uint32 cDesiredThreads = numThreads > 0 ? numThreads : cProcessors;
const uint32 cThreads = cDesiredThreads >= kMaxWorkers ? kMaxWorkers : cDesiredThreads;
for( uint32 i = 0; i < cThreads; ++i ) {
#ifdef _MSC_VER
# pragma warning( push )
# pragma warning( disable:4316 ) //object allocated on the heap may not be aligned 64
#endif
m_pWorkers[ i ] = new LWorker( *this, i );
#ifdef _MSC_VER
# pragma warning( pop )
#endif
if( !AX_VERIFY_NOT_NULL( m_pWorkers[ i ] ) ) {
while( i > 0 ) {
delete m_pWorkers[ i - 1 ];
--i;
}
return false;
}
}
#ifdef _WIN32
// Peg the main thread to one specific processor core for QueryPerformanceCounter() improvement
SetThreadAffinityMask( GetCurrentThread(), 1<<0 );
#endif
m_pThreads[ 0 ] = nullptr;
for( uint32 i = 1; i < cThreads; ++i ) {
m_pThreads[ i ] = new LWorkerThread( *m_pWorkers[ i ] );
if( !AX_VERIFY_NOT_NULL( m_pThreads[ i ] ) ) {
while( i > 0 ) {
delete m_pThreads[ i - 1 ];
--i;
}
for( i = 0; i < cThreads; ++i ) {
delete m_pWorkers[ i ];
}
return false;
}
#if AX_THREAD_MODEL == AX_THREAD_MODEL_WINDOWS
const HANDLE hThread = m_pThreads[ i ]->GetNative_MSWin();
SetThreadAffinityMask( hThread, DWORD_PTR( 1 )<<i );
#endif
}
m_cWorkers = cThreads;
m_cSleepingWorkers = 0;
m_bIsQuitting = false;
m_cFrameChains = 0;
m_cFrameTasks = 0;
#if !AX_ASYNC_LOCAL_WORK_ENABLED
m_cSubmittedChains = 0;
#endif
#if !AX_ASYNC_PER_WORKER_IDLE_FLAG_ENABLED
m_cIdleWorkers = m_cWorkers;
#endif
AX_MEMORY_BARRIER(); //must be set before threads start (this is just paranoia)
for( uint32 i = 1; i < cThreads; ++i ) {
m_pThreads[ i ]->Start();
}
return true;
}
示例15: SetThreadAffinityMask
void JUCE_CALLTYPE Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
{
SetThreadAffinityMask (GetCurrentThread(), affinityMask);
}