- /* context exception handlers */
- __xbt_ex_ctx = xbt_ctx_sysv_ex_ctx;
- __xbt_ex_terminate = xbt_ctx_sysv_ex_terminate;
-}
-
-static int smx_ctx_sysv_factory_create_maestro_context(smx_process_t *maestro)
-{
- smx_ctx_sysv_t context = xbt_new0(s_smx_ctx_sysv_t, 1);
+ if (smx_parallel_contexts) {
+#ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */
+ parmap = xbt_parmap_new(2);
+ (*factory)->runall = smx_ctx_sysv_runall_parallel;
+ (*factory)->self = smx_ctx_sysv_self_parallel;
+#else
+ THROW0(arg_error, 0, "No thread support for parallel context execution");
+#endif
+ }else{
+ (*factory)->runall = smx_ctx_sysv_runall;
+ }
+}
+
+int smx_ctx_sysv_factory_finalize(smx_context_factory_t *factory)
+{
+ if(parmap)
+ xbt_parmap_destroy(parmap);
+ return smx_ctx_base_factory_finalize(factory);
+}
+
+smx_context_t
+smx_ctx_sysv_create_context_sized(size_t size, xbt_main_func_t code,
+ int argc, char **argv,
+ void_pfn_smxprocess_t cleanup_func,
+ void *data)
+{
+ union u_ctx_addr ctx_addr;
+ smx_ctx_sysv_t context =
+ (smx_ctx_sysv_t) smx_ctx_base_factory_create_context_sized(size,
+ code,
+ argc,
+ argv,
+ cleanup_func,
+ data);
+
+ /* If the user provided a function for the process then use it
+ otherwise is the context for maestro */
+ if (code) {
+
+ xbt_assert2(getcontext(&(context->uc)) == 0,
+ "Error in context saving: %d (%s)", errno,
+ strerror(errno));
+
+ context->uc.uc_link = NULL;
+
+ context->uc.uc_stack.ss_sp =
+ pth_skaddr_makecontext(context->stack, CONTEXT_STACK_SIZE);
+
+ context->uc.uc_stack.ss_size =
+ pth_sksize_makecontext(context->stack, CONTEXT_STACK_SIZE);