-
-#include "threadpool_private.h"
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_threadpool, xbt,
- "threadpool: pool of worker threads");
-
-static void *_xbt_tpool_worker_main(void *tpool);
-
-unsigned long tpoolcounter = 0; /* Debug purposes */
-
-xbt_tpool_t xbt_tpool_new(unsigned int num_workers, unsigned int max_jobs)
+#include "gras_config.h"
+#include <unistd.h>
+
+#ifndef _XBT_WIN32
+#include <sys/syscall.h>
+#endif
+
+#ifdef HAVE_FUTEX_H
+#include <linux/futex.h>
+#endif
+
+#include "xbt/parmap.h"
+#include "xbt/log.h"
+#include "xbt/function_types.h"
+#include "xbt/dynar.h"
+#include "xbt/xbt_os_thread.h"
+#include "xbt/sysdep.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_parmap, xbt, "parmap: parallel map");
+XBT_LOG_NEW_SUBCATEGORY(xbt_parmap_unit, xbt_parmap, "parmap unit testing");
+
+typedef enum {
+ PARMAP_WORK = 0,
+ PARMAP_DESTROY
+} e_xbt_parmap_flag_t;
+
+static void xbt_parmap_start(xbt_parmap_t parmap);
+static void xbt_parmap_signal(xbt_parmap_t parmap);
+static void xbt_parmap_wait(xbt_parmap_t parmap);
+static void xbt_parmap_end(xbt_parmap_t parmap);
+static void *xbt_parmap_worker_main(void *parmap);
+
+#ifdef HAVE_FUTEX_H
+static void futex_wait(int *uaddr, int val);
+static void futex_wake(int *uaddr, int val);
+#endif
+
+/**
+ * \brief Parallel map structure
+ */
+typedef struct s_xbt_parmap {
+ e_xbt_parmap_flag_t status; /* is the parmap active or being destroyed? */
+
+ int work; /* index of the current round (1 is the first) */
+ int done; /* number of rounds already done */
+ unsigned int thread_counter; /* number of threads currently working */
+ unsigned int num_workers; /* total number of worker threads */
+ unsigned int workers_max_id; /* id of the next worker thread to create */
+ void_f_pvoid_t fun; /* function to run in parallel on each element of data */
+ xbt_dynar_t data; /* parameters to pass to fun in parallel */
+ unsigned int index; /* index of the next element of data to pick */
+} s_xbt_parmap_t;
+
+/**
+ * \brief Creates a parallel map object
+ * \param num_workers number of worker threads to create
+ * \return the parmap created
+ */
+xbt_parmap_t xbt_parmap_new(unsigned int num_workers)