First cut of OpenThrads::Affinity support for Win32.
This commit is contained in:
@@ -106,8 +106,7 @@ namespace OpenThreads {
|
||||
// release the thread that created this thread.
|
||||
pd->threadStartedBlock.release();
|
||||
|
||||
if (0 <= pd->cpunum)
|
||||
thread->setProcessorAffinity(pd->cpunum);
|
||||
thread->setProcessorAffinity(pd->affinity);
|
||||
|
||||
try{
|
||||
thread->run();
|
||||
@@ -241,7 +240,6 @@ Win32ThreadPrivateData::Win32ThreadPrivateData()
|
||||
threadPolicy = Thread::THREAD_SCHEDULE_DEFAULT;
|
||||
detached = false;
|
||||
cancelEvent.set(CreateEvent(NULL,TRUE,FALSE,NULL));
|
||||
cpunum = -1;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -575,10 +573,10 @@ size_t Thread::getStackSize() {
|
||||
//
|
||||
// Use: public
|
||||
//
|
||||
int Thread::setProcessorAffinity( unsigned int cpunum )
|
||||
int Thread::setProcessorAffinity( const Affinity& affinity )
|
||||
{
|
||||
Win32ThreadPrivateData *pd = static_cast<Win32ThreadPrivateData *> (_prvData);
|
||||
pd->cpunum = cpunum;
|
||||
pd->affinity = affinity;
|
||||
if (!pd->isRunning)
|
||||
return 0;
|
||||
|
||||
@@ -586,7 +584,34 @@ int Thread::setProcessorAffinity( unsigned int cpunum )
|
||||
return -1;
|
||||
|
||||
|
||||
DWORD affinityMask = 0x1 << cpunum ; // thread affinity mask
|
||||
unsigned int numprocessors = OpenThreads::GetNumberOfProcessors();
|
||||
|
||||
DWORD affinityMask = 0x0;
|
||||
if (affinity)
|
||||
{
|
||||
for(Affinity::ActiveCPUs::const_iterator itr = affinity.activeCPUs.begin();
|
||||
itr != affinity.activeCPUs.end();
|
||||
++itr)
|
||||
{
|
||||
unsigned int cpunum = *itr;
|
||||
if (cpunum<numprocessors)
|
||||
{
|
||||
std::cout<<" setting CPU : "<< *itr<<std::endl;
|
||||
affinityMask |= (0x1<<cpunum);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int cpunum = 0; cpunum < numprocessors; ++cpunum)
|
||||
{
|
||||
std::cout<<" Fallback setting CPU : "<< cpunum<<std::endl;
|
||||
|
||||
affinityMask |= (0x1<<cpunum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DWORD_PTR res =
|
||||
SetThreadAffinityMask
|
||||
(
|
||||
@@ -682,14 +707,14 @@ int OpenThreads::GetNumberOfProcessors()
|
||||
return sysInfo.dwNumberOfProcessors;
|
||||
}
|
||||
|
||||
int OpenThreads::SetProcessorAffinityOfCurrentThread(unsigned int cpunum)
|
||||
int OpenThreads::SetProcessorAffinityOfCurrentThread(const Affinity& affinity)
|
||||
{
|
||||
Thread::Init();
|
||||
|
||||
Thread* thread = Thread::CurrentThread();
|
||||
if (thread)
|
||||
{
|
||||
return thread->setProcessorAffinity(cpunum);
|
||||
return thread->setProcessorAffinity(affinity);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenThreads {
|
||||
//
|
||||
friend class Thread;
|
||||
//-------------------------------------------------------------------------
|
||||
// We're friendly to Win32PrivateActions, so it can get at some
|
||||
// We're friendly to Win32PrivateActions, so it can get at some
|
||||
// variables.
|
||||
//
|
||||
friend class ThreadPrivateActions;
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
|
||||
Block threadStartedBlock;
|
||||
|
||||
int cancelMode; // 0 - deffered (default) 1-asynch 2-disabled
|
||||
int cancelMode; // 0 - deffered (default) 1-asynch 2-disabled
|
||||
|
||||
bool detached;
|
||||
|
||||
@@ -56,7 +56,7 @@ private:
|
||||
|
||||
int uniqueId;
|
||||
|
||||
int cpunum;
|
||||
Affinity affinity;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user