Revision: 54974
          http://brlcad.svn.sourceforge.net/brlcad/?rev=54974&view=rev
Author:   brlcad
Date:     2013-03-29 16:46:29 +0000 (Fri, 29 Mar 2013)
Log Message:
-----------
take a stab at implementing thread affinity for windows as well (hah, in 
advance of windows threading).  using bu_parallel_id() to set the cpu number. 
earned fewest line count badge (albeit untested)

Modified Paths:
--------------
    brlcad/trunk/src/libbu/affinity.c

Modified: brlcad/trunk/src/libbu/affinity.c
===================================================================
--- brlcad/trunk/src/libbu/affinity.c   2013-03-29 16:45:20 UTC (rev 54973)
+++ brlcad/trunk/src/libbu/affinity.c   2013-03-29 16:46:29 UTC (rev 54974)
@@ -45,6 +45,10 @@
 #  include <mach/mach.h>
 #endif
 
+#ifdef HAVE_WINDOWS_H
+#  include <windows.h>
+#endif
+
 #include "bu.h"
 
 
@@ -56,7 +60,7 @@
     /* Linux and BSD pthread affinity */
 
     pthread_t curr_thread = pthread_self();    /* Get current thread */
-    int cpulim = bu_avail_cpus();              /* Max number of CPUs available 
for the process */
+    int ncpu = bu_avail_cpus();                        /* Max number of CPUs 
available for the process */
     int status;                                        /* Status of thread 
setting/getting */
     int cpu = 0;                               /* Default CPU number */
     int j;                                     /* Variable for iteration. */
@@ -67,17 +71,15 @@
     cpuset_t set_of_cpus;
 #endif
 
-
     CPU_ZERO(&set_of_cpus);
 
-    for (j = 0; j < cpulim; j++) {
+    for (j = 0; j < ncpu; j++) {
        /* Set affinity mask to include CPUs 0 to max available CPU */
        CPU_SET(j, &set_of_cpus);
     }
 
     /* Check current affinity mask assigned to thread */
     status = pthread_getaffinity_np(curr_thread, sizeof(set_of_cpus), 
&set_of_cpus);
-
     if (status != 0) {
        /* Error in getting affinity mask */
        return -1;
@@ -98,7 +100,6 @@
 
     /* set affinity mask of current thread */
     status = pthread_setaffinity_np(curr_thread, sizeof(set_of_cpus), 
&set_of_cpus);
-
     if (status != 0) {
        /* Error in setting affinity mask */
        return -1;
@@ -134,6 +135,12 @@
 
     return 0;
 
+#elif defined(HAVE_WINDOWS_H)
+    BOOL ret = SetThreadAffinityMask(GetCurrentThread(), 1 << 
bu_parallel_id());
+    if (ret  == 0)
+       return -1;
+
+    return 0;
 #else
 
     /* don't know how to set thread affinity on this platform */

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete 
for recognition, cash, and the chance to get your game on Steam. 
$5K grand prize plus 10 genre and skill prizes. Submit your demo 
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to