+
+// **** Parallel code
+
+#ifdef CONTEXT_THREADS
+
+static void smx_ctx_boost_stop_parallel(smx_context_t context)
+{
+ smx_ctx_base_stop(context);
+ smx_ctx_boost_suspend_parallel(context);
+}
+
+static void smx_ctx_boost_suspend_parallel(smx_context_t context)
+{
+ smx_process_t next_work = (smx_process_t) xbt_parmap_next(boost_parmap);
+ smx_ctx_boost_t next_context;
+
+ if (next_work != NULL) {
+ XBT_DEBUG("Run next process");
+ next_context = (smx_ctx_boost_t) next_work->context;
+ }
+ else {
+ XBT_DEBUG("No more processes to run");
+ unsigned long worker_id =
+ (unsigned long) xbt_os_thread_get_specific(boost_worker_id_key);
+ next_context = boost_workers_context[worker_id];
+ }
+
+ SIMIX_context_set_current((smx_context_t) next_context);
+ boost::context::jump_fcontext(
+ ((smx_ctx_boost_t)context)->fc, next_context->fc, (intptr_t)next_context);
+}
+
+static void smx_ctx_boost_resume_parallel(smx_process_t process)
+{
+ unsigned long worker_id = __sync_fetch_and_add(&boost_threads_working, 1);
+ xbt_os_thread_set_specific(boost_worker_id_key, (void*) worker_id);
+
+ smx_ctx_boost_t worker_context = (smx_ctx_boost_t)SIMIX_context_self();
+ boost_workers_context[worker_id] = worker_context;
+ smx_ctx_boost_t context = (smx_ctx_boost_t) process->context;
+
+ SIMIX_context_set_current((smx_context_t) context);
+ boost::context::jump_fcontext(worker_context->fc, context->fc,
+ (intptr_t)context);
+}
+
+static void smx_ctx_boost_runall_parallel(void)
+{
+ boost_threads_working = 0;
+ xbt_parmap_apply(boost_parmap, (void_f_pvoid_t) smx_ctx_boost_resume_parallel,
+ simix_global->process_to_run);
+}
+
+#endif