- mycount = __sync_add_and_fetch(&parmap->thread_counter, 1);
- if (mycount == parmap->num_workers) {
- /* all workers have finished, wake the controller */
- parmap->done++;
- futex_wake(&parmap->done, 1);
+/**
+ * \brief Wakes all workers and waits for them to finish the tasks.
+ *
+ * This function is called by the controller thread.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_busy_signal(xbt_parmap_t parmap)
+{
+ parmap->thread_counter = 0;
+ parmap->work++;
+
+ if (parmap->status == XBT_PARMAP_WORK) {
+ /* also work myself */
+ void* work = xbt_parmap_next(parmap);
+ while (work != NULL) {
+ parmap->fun(work);
+ work = xbt_parmap_next(parmap);
+ }
+ }
+
+ /* I have finished, wait for the others */
+ __sync_add_and_fetch(&parmap->thread_counter, 1);
+ while (parmap->thread_counter < parmap->num_workers) {
+ xbt_os_thread_yield();
+ }
+}
+
+/**
+ * \brief Waits for some work to process.
+ *
+ * This function is called by each worker thread (not including the controller)
+ * when it has no more work to do.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_busy_wait(xbt_parmap_t parmap)
+{
+ int work = parmap->work;
+ __sync_add_and_fetch(&parmap->thread_counter, 1);
+
+ /* wait for more work */
+ while (parmap->work == work) {
+ xbt_os_thread_yield();