Introduced new OpenThreads::Affinity class to wrap up specification of thread affinity.

Simplified the OpenThreads::SetProcessorAffinityOfCurrentThread/Thread::SetProcessorAffinity() to utilize the new Affinity class
This commit is contained in:
Robert Osfield
2016-09-27 10:50:38 +01:00
parent 0f8a5a86e2
commit bc44da49e6
5 changed files with 108 additions and 83 deletions

View File

@@ -23,6 +23,7 @@
#include <sys/types.h>
#include <OpenThreads/Mutex>
#include <OpenThreads/Affinity>
namespace OpenThreads {
@@ -34,19 +35,11 @@ namespace OpenThreads {
*/
extern OPENTHREAD_EXPORT_DIRECTIVE int GetNumberOfProcessors();
/**
* Set the processor affinity mask of current thread. If you want to allow thread to run on any processor core use ~0ul for the cpumask
*/
extern OPENTHREAD_EXPORT_DIRECTIVE int SetProcessorAffinityMaskOfCurrentThread(unsigned long cpumask);
/**
* Set the processor affinity of current thread.
*/
inline int SetProcessorAffinityOfCurrentThread(unsigned int cpunum)
{
unsigned long cpumask = 1ul << cpunum;
return SetProcessorAffinityMaskOfCurrentThread(cpumask);
}
int SetProcessorAffinityOfCurrentThread(const Affinity& affinity);
/**
* @class Thread
@@ -338,27 +331,13 @@ public:
void* getImplementation(){ return _prvData; };
/** Set the Thread's processor affinity to a single CPU.
/** Set the Thread's processor affinity to all, a single CPU or multiple CPU's
* This call must be made before
* start() or startThread() and has no effect after the thread
* has been running. Returns 0 on success, implementation's
* error on failure, or -1 if ignored.
*/
int setProcessorAffinity( unsigned int cpunum )
{
unsigned long cpumask = 1ul << cpunum;
return setProcessorAffinityMask(cpumask);
}
/** Set the Thread's processor affinity to a one or more CPU's using mask.
* If you want this threadd to run on any processor core then use a cpumask of ~0ul
* This call must be made before
* start() or startThread() and has no effect after the thread
* has been running. Returns 0 on success, implementation's
* error on failure, or -1 if ignored.
*/
int setProcessorAffinityMask( unsigned long cpumask);
int setProcessorAffinity( const Affinity& affinity);
/** microSleep method, equivalent to the posix usleep(microsec).