vsg  1.1.0
VulkanSceneGraph library
Affinity.h
1 /* <editor-fold desc="MIT License">
2 
3 Copyright(c) 2020 Robert Osfield
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 
7 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 
9 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 
11 </editor-fold> */
12 
13 #pragma once
14 
15 #include <vsg/core/Export.h>
16 
17 #include <set>
18 #include <thread>
19 
20 namespace vsg
21 {
22 
24  struct Affinity
25  {
26  Affinity() {}
27 
28  explicit Affinity(uint32_t cpu, uint32_t num = 1)
29  {
30  for (uint32_t i = 0; i < num; ++i) cpus.insert(cpu + i);
31  }
32 
33  std::set<uint32_t> cpus;
34 
35  operator bool() const { return !cpus.empty(); }
36  };
37 
39  extern VSG_DECLSPEC void setAffinity(std::thread& thread, const Affinity& affinity);
40 
43  extern VSG_DECLSPEC void setAffinity(const Affinity& affinity);
44 
45 } // namespace vsg
Affinity struct provides a set of cpu ids that a thread can be set to have affinity to.
Definition: Affinity.h:25