OpenThreads
Affinity
Go to the documentation of this file.
1/* -*-c++-*- OpenThreads library, Copyright (C) 2016 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14
15//
16// Affinity - C++ Affinity class
17// ~~~~~~~~
18//
19
20#ifndef _OPENTHREADS_AFFINITY_
21#define _OPENTHREADS_AFFINITY_
22
23#include <set>
24#include <OpenThreads/Mutex>
25
26namespace OpenThreads {
27
34{
35public:
36
38
39 Affinity(unsigned int cpuNumber) { activeCPUs.insert(cpuNumber); }
40
41 Affinity(unsigned int cpuNumber, unsigned int cpuCount) { while(cpuCount>0) { activeCPUs.insert(cpuNumber++); --cpuCount; } }
42
43 Affinity(const Affinity& rhs) : activeCPUs(rhs.activeCPUs) {}
44
45 Affinity& operator = (const Affinity& rhs) { if (&rhs!=this) { activeCPUs = rhs.activeCPUs; } return *this; }
46
47
49 void add(unsigned int cpuNmber) { activeCPUs.insert(cpuNmber); }
50
52 void remove(unsigned int cpuNmber) { activeCPUs.erase(cpuNmber); }
53
55 operator bool () const { return !activeCPUs.empty(); }
56
57 typedef std::set<unsigned int> ActiveCPUs;
58
61};
62
63}
64
65#endif // !_OPENTHREADS_THREAD_
Definition Affinity:26
void add(unsigned int cpuNmber)
add a specified cpu core from the list to have affinity to.
Definition Affinity:49
Affinity(unsigned int cpuNumber)
Definition Affinity:39
Affinity()
Definition Affinity:37
Affinity & operator=(const Affinity &rhs)
Definition Affinity:45
ActiveCPUs activeCPUs
Set of CPUs that a thread should have affinity to.
Definition Affinity:60
std::set< unsigned int > ActiveCPUs
Definition Affinity:57
Affinity(unsigned int cpuNumber, unsigned int cpuCount)
Definition Affinity:41
void remove(unsigned int cpuNmber)
remove a specified cpu core from the list to have affinity to.
Definition Affinity:52
Affinity(const Affinity &rhs)
Definition Affinity:43

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenThreads by doxygen 1.14.0.