|
27 | 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
28 | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 | */ |
30 | | - |
| 30 | + |
31 | 31 | #include <cpuaff/cpuaff.hpp> |
32 | 32 | #include <iostream> |
33 | 33 |
|
34 | 34 | int main(int argc, char *argv[]) |
35 | 35 | { |
36 | 36 | cpuaff::affinity_manager manager; |
37 | | - |
38 | | - if (manager.initialize(false)) |
39 | | - { |
| 37 | + |
| 38 | + if (manager.initialize()) |
| 39 | + { |
40 | 40 | cpuaff::affinity_stack stack(manager); |
41 | | - |
42 | | - cpuaff::cpu_set_type cpus; |
| 41 | + |
| 42 | + cpuaff::cpu_set cpus; |
43 | 43 | manager.get_affinity(cpus); |
44 | | - |
| 44 | + |
45 | 45 | std::cout << "Initial Affinity:" << std::endl; |
46 | | - |
47 | | - cpuaff::cpu_set_type::iterator i = cpus.begin(); |
48 | | - cpuaff::cpu_set_type::iterator iend = cpus.end(); |
49 | | - |
50 | | - for ( ; i != iend; ++i) |
| 46 | + |
| 47 | + cpuaff::cpu_set::iterator i = cpus.begin(); |
| 48 | + cpuaff::cpu_set::iterator iend = cpus.end(); |
| 49 | + |
| 50 | + for (; i != iend; ++i) |
51 | 51 | { |
52 | 52 | std::cout << " " << (*i) << std::endl; |
53 | 53 | } |
54 | | - |
| 54 | + |
55 | 55 | std::cout << std::endl; |
56 | | - |
| 56 | + |
57 | 57 | stack.push_affinity(); |
58 | | - |
| 58 | + |
59 | 59 | // set the affinity to all the processing units on the first core |
60 | | - cpuaff::cpu_set_type core_0; |
| 60 | + cpuaff::cpu_set core_0; |
61 | 61 | manager.get_cpus_by_core(core_0, 0); |
62 | | - |
| 62 | + |
63 | 63 | manager.set_affinity(core_0); |
64 | 64 | manager.get_affinity(cpus); |
65 | | - |
| 65 | + |
66 | 66 | std::cout << "Affinity After Calling set_affinity():" << std::endl; |
67 | 67 | i = cpus.begin(); |
68 | 68 | iend = cpus.end(); |
69 | | - |
70 | | - for ( ; i != iend; ++i) |
| 69 | + |
| 70 | + for (; i != iend; ++i) |
71 | 71 | { |
72 | 72 | std::cout << " " << (*i) << std::endl; |
73 | 73 | } |
74 | | - |
| 74 | + |
75 | 75 | std::cout << std::endl; |
76 | | - |
| 76 | + |
77 | 77 | // restore the affinity to its initial value |
78 | 78 | stack.pop_affinity(); |
79 | | - |
| 79 | + |
80 | 80 | manager.get_affinity(cpus); |
81 | | - |
| 81 | + |
82 | 82 | std::cout << "Affinity After Calling pop_affinity():" << std::endl; |
83 | 83 | i = cpus.begin(); |
84 | 84 | iend = cpus.end(); |
85 | | - |
86 | | - for ( ; i != iend; ++i) |
| 85 | + |
| 86 | + for (; i != iend; ++i) |
87 | 87 | { |
88 | 88 | std::cout << " " << (*i) << std::endl; |
89 | 89 | } |
90 | | - |
| 90 | + |
91 | 91 | return 0; |
92 | 92 | } |
93 | | - |
| 93 | + |
94 | 94 | std::cerr << "cpuaff: unable to load cpus." << std::endl; |
95 | 95 | return -1; |
96 | 96 | } |
0 commit comments