Revision: 54941
http://brlcad.svn.sourceforge.net/brlcad/?rev=54941&view=rev
Author: brlcad
Date: 2013-03-28 17:34:01 +0000 (Thu, 28 Mar 2013)
Log Message:
-----------
hook up to the thread local storage so bu_parallel_id() can track our thread
number, fix record keeping that keeps track of how many started/finished
Modified Paths:
--------------
brlcad/trunk/src/libbu/parallel.c
Modified: brlcad/trunk/src/libbu/parallel.c
===================================================================
--- brlcad/trunk/src/libbu/parallel.c 2013-03-28 15:47:45 UTC (rev 54940)
+++ brlcad/trunk/src/libbu/parallel.c 2013-03-28 17:34:01 UTC (rev 54941)
@@ -120,6 +120,7 @@
void (*user_func)(int, genptr_t);
genptr_t user_arg;
int cpu_id;
+ int counted;
};
@@ -141,17 +142,11 @@
/* user function to run in parallel */
static void (*parallel_func)(int, genptr_t);
-/* !!! work-in-progress !!! */
-/* __thread */ void *cpu = NULL;
-
int
bu_parallel_id(void)
{
- if (cpu)
- return *(int *)cpu;
- else
- return 0;
+ return thread_get_cpu();
}
@@ -349,10 +344,23 @@
HIDDEN void
parallel_interface_arg(struct thread_data *user_thread_data)
{
- cpu = &user_thread_data->cpu_id;
parallel_set_affinity();
+
+ thread_set_cpu(user_thread_data->cpu_id);
+
+ if (!user_thread_data->counted) {
+ bu_semaphore_acquire(BU_SEM_SYSCALL);
+ parallel_nthreads_started++;
+ bu_semaphore_release(BU_SEM_SYSCALL);
+ }
+
(*(user_thread_data->user_func))(user_thread_data->cpu_id,
user_thread_data->user_arg);
- cpu = NULL; /* sanity */
+
+ if (!user_thread_data->counted) {
+ bu_semaphore_acquire(BU_SEM_SYSCALL);
+ parallel_nthreads_finished++;
+ bu_semaphore_release(BU_SEM_SYSCALL);
+ }
}
@@ -379,15 +387,15 @@
user_thread_data_pi.user_arg = parallel_arg;
bu_semaphore_acquire(BU_SEM_SYSCALL);
- user_thread_data_pi.cpu_id = parallel_nthreads_started++ + 1;
- cpu = &user_thread_data_pi.cpu_id;
+ user_thread_data_pi.cpu_id = parallel_nthreads_started++;
bu_semaphore_release(BU_SEM_SYSCALL);
+ user_thread_data_pi.counted = 1;
+
parallel_interface_arg(&user_thread_data_pi);
bu_semaphore_acquire(BU_SEM_SYSCALL);
parallel_nthreads_finished++;
- cpu = NULL; /* sanity */
bu_semaphore_release(BU_SEM_SYSCALL);
}
@@ -447,6 +455,7 @@
user_thread_data_bu[x].user_func = func;
user_thread_data_bu[x].user_arg = arg;
user_thread_data_bu[x].cpu_id = x + 1; /* index from 1 */
+ user_thread_data_bu[x].counted = 0;
}
/* if we're in debug mode, allow additional cpus */
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Own the Future-Intel® 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://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits