[vlc-commits] vlc_GetCPUCount: use counting functions instead of loop

Rémi Denis-Courmont git at videolan.org
Wed Jun 29 20:03:35 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jun 29 21:02:58 2011 +0300| [2011fd9a13fb78416dbbfc17e893a6acec4c94d9] | committer: Rémi Denis-Courmont

vlc_GetCPUCount: use counting functions instead of loop

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2011fd9a13fb78416dbbfc17e893a6acec4c94d9
---

 src/posix/thread.c |    5 +----
 src/win32/thread.c |   10 +---------
 2 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/src/posix/thread.c b/src/posix/thread.c
index 93b7ca1..561f93a 100644
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
@@ -1038,10 +1038,7 @@ unsigned vlc_GetCPUCount(void)
     if (sched_getaffinity (getpid(), sizeof (cpu), &cpu) < 0)
         return 1;
 
-    unsigned count = 0;
-    for (unsigned i = 0; i < CPU_SETSIZE; i++)
-        count += CPU_ISSET(i, &cpu) != 0;
-    return count;
+    return CPU_COUNT (&cpu);
 
 #elif defined(__APPLE__)
     int count;
diff --git a/src/win32/thread.c b/src/win32/thread.c
index dbd2e51..9b83f84 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -916,15 +916,7 @@ unsigned vlc_GetCPUCount (void)
     DWORD system;
 
     if (GetProcessAffinityMask (GetCurrentProcess(), &process, &system))
-    {
-        unsigned count = 0;
-        while (system)
-        {
-            count++;
-            system >>= 1;
-        }
-        return count;
-     }
+        return popcount (system);
 #endif
      return 1;
 }



More information about the vlc-commits mailing list