OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef _GNU_SOURCE | 8 #ifndef _GNU_SOURCE |
9 #define _GNU_SOURCE //for pthread_setaffinity_np | 9 #define _GNU_SOURCE //for pthread_setaffinity_np |
10 #endif | 10 #endif |
11 | 11 |
12 #include "SkThreadUtils.h" | 12 #include "SkThreadUtils.h" |
13 #include "SkThreadUtils_pthread.h" | 13 #include "SkThreadUtils_pthread.h" |
14 | 14 |
15 #include <pthread.h> | 15 #include <pthread.h> |
16 #ifdef __FreeBSD__ | |
17 #include <pthread_np.h> | |
18 #endif | |
19 | |
20 #if defined(__FreeBSD__) || defined(__NetBSD__) | |
21 #define cpu_set_t cpuset_t | |
bungeman-skia
2013/08/06 20:44:12
isn't this what typedef is for?
| |
22 #endif | |
23 | |
24 #ifndef CPU_COUNT | |
25 static int CPU_COUNT(cpu_set_t *set) { | |
26 int count = 0; | |
27 for (int i = 0; i < CPU_SETSIZE; i++) { | |
28 if (CPU_ISSET(i, set)) { | |
29 count++; | |
30 } | |
31 } | |
32 return count; | |
33 } | |
34 #endif /* !CPU_COUNT */ | |
16 | 35 |
17 static int nth_set_cpu(unsigned int n, cpu_set_t* cpuSet) { | 36 static int nth_set_cpu(unsigned int n, cpu_set_t* cpuSet) { |
18 n %= CPU_COUNT(cpuSet); | 37 n %= CPU_COUNT(cpuSet); |
19 for (unsigned int setCpusSeen = 0, currentCpu = 0; true; ++currentCpu) { | 38 for (unsigned int setCpusSeen = 0, currentCpu = 0; true; ++currentCpu) { |
20 if (CPU_ISSET(currentCpu, cpuSet)) { | 39 if (CPU_ISSET(currentCpu, cpuSet)) { |
21 ++setCpusSeen; | 40 ++setCpusSeen; |
22 if (setCpusSeen > n) { | 41 if (setCpusSeen > n) { |
23 return currentCpu; | 42 return currentCpu; |
24 } | 43 } |
25 } | 44 } |
(...skipping 11 matching lines...) Expand all Loading... | |
37 return false; | 56 return false; |
38 } | 57 } |
39 | 58 |
40 cpu_set_t cpuset; | 59 cpu_set_t cpuset; |
41 CPU_ZERO(&cpuset); | 60 CPU_ZERO(&cpuset); |
42 CPU_SET(nth_set_cpu(processor, &parentCpuset), &cpuset); | 61 CPU_SET(nth_set_cpu(processor, &parentCpuset), &cpuset); |
43 return 0 == pthread_setaffinity_np(pthreadData->fPThread, | 62 return 0 == pthread_setaffinity_np(pthreadData->fPThread, |
44 sizeof(cpu_set_t), | 63 sizeof(cpu_set_t), |
45 &cpuset); | 64 &cpuset); |
46 } | 65 } |
OLD | NEW |