Signed-off-by: Justin Cinkelj <justin.cink...@xlab.si>
---
 include/api/sched.h | 12 ++++--------
 libc/pthread.cc     |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/include/api/sched.h b/include/api/sched.h
index 14f24de..925ea98 100644
--- a/include/api/sched.h
+++ b/include/api/sched.h
@@ -83,6 +83,8 @@ typedef       struct {
        __cpu_mask      __bits[_NCPUWORDS];
 } cpu_set_t;
 
+int __sched_cpucount (size_t __setsize, const cpu_set_t *__setp);
+
 inline static void CPU_ZERO(cpu_set_t *cpuset) {
     size_t i;
     for (i = 0; i < _NCPUWORDS; i++) {
@@ -118,14 +120,8 @@ inline static int CPU_ISSET(size_t n, const cpu_set_t 
*cpuset) {
     return (cpuset->__bits[__cpuset_word(n)] & __cpuset_mask(n)) != 0;
 }
 
-inline static int CPU_COUNT(const cpu_set_t *cpuset) {
-    size_t i;
-    int count = 0;
-    for (i = 0; i < _NCPUWORDS; i++) {
-        count += __builtin_popcountl(cpuset->__bits[i]);
-    }
-    return count;
-}
+#define CPU_COUNT_S(setsize, cpuset) __sched_cpucount(setsize, cpuset)
+#define CPU_COUNT(cpuset) __sched_cpucount(_NCPUWORDS*sizeof (__cpu_mask), 
cpuset)
 
 inline static size_t CPU_ALLOC_SIZE(size_t count) {
     return ((count + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask);
diff --git a/libc/pthread.cc b/libc/pthread.cc
index 1e6d357..ac7b3f0 100644
--- a/libc/pthread.cc
+++ b/libc/pthread.cc
@@ -943,7 +943,7 @@ int pthread_attr_setaffinity_np(pthread_attr_t *attr, 
size_t cpusetsize,
 static int setaffinity(sched::thread* t, size_t cpusetsize,
         const cpu_set_t *cpuset)
 {
-    int count = CPU_COUNT(cpuset);
+    int count = CPU_COUNT_S(cpusetsize, cpuset);
     if (count == 0) {
         // Having a cpuset with no CPUs in it is invalid.
         return EINVAL;
-- 
2.5.5

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to