+static int smx_ctx_raw_factory_finalize(smx_context_factory_t *factory);
+static smx_context_t smx_ctx_raw_create_context(xbt_main_func_t code, int argc,
+ char **argv, void_pfn_smxprocess_t cleanup_func, void *data);
+static void smx_ctx_raw_free(smx_context_t context);
+static void smx_ctx_raw_wrapper(smx_ctx_raw_t context);
+static void smx_ctx_raw_stop(smx_context_t context);
+static void smx_ctx_raw_suspend_serial(smx_context_t context);
+static void smx_ctx_raw_resume_serial(smx_process_t first_process);
+static void smx_ctx_raw_runall_serial(void);
+static void smx_ctx_raw_suspend_parallel(smx_context_t context);
+static void smx_ctx_raw_resume_parallel(smx_process_t first_process);
+static void smx_ctx_raw_runall_parallel(void);
+static void smx_ctx_raw_runall(void);
+
+/**
+ * \brief Initializes the raw context factory.
+ * \param factory where to initialize the factory
+ */
+void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory)
+{
+ XBT_VERB("Using raw contexts. Because the glibc is just not good enough for us.");
+ smx_ctx_base_factory_init(factory);
+
+ (*factory)->finalize = smx_ctx_raw_factory_finalize;
+ (*factory)->create_context = smx_ctx_raw_create_context;
+ /* Do not overload that method (*factory)->finalize */
+ (*factory)->free = smx_ctx_raw_free;
+ (*factory)->stop = smx_ctx_raw_stop;
+ (*factory)->name = "smx_raw_context_factory";
+
+ if (SIMIX_context_is_parallel()) {
+#ifdef CONTEXT_THREADS
+ int nthreads = SIMIX_context_get_nthreads();
+ raw_parmap = xbt_parmap_new(nthreads, SIMIX_context_get_parallel_mode());
+ raw_workers_stacks = xbt_new(raw_stack_t, nthreads);
+ xbt_os_thread_key_create(&raw_worker_id_key);
+#endif
+ if (SIMIX_context_get_parallel_threshold() > 1) {
+ /* choose dynamically */
+ (*factory)->runall = smx_ctx_raw_runall;
+ (*factory)->suspend = NULL;
+ }
+ else {
+ /* always parallel */
+ (*factory)->runall = smx_ctx_raw_runall_parallel;
+ (*factory)->suspend = smx_ctx_raw_suspend_parallel;
+ }
+ }
+ else {
+ /* always serial */
+ (*factory)->runall = smx_ctx_raw_runall_serial;
+ (*factory)->suspend = smx_ctx_raw_suspend_serial;
+ }
+#ifdef TIME_BENCH
+ timer = xbt_os_timer_new();
+#endif
+}