1 /* context_base - Code factorization across context switching implementations */
3 /* Copyright (c) 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/function_types.h"
11 #include "simgrid/simix.h"
12 #include "smx_private.h"
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(bindings);
17 void smx_ctx_base_factory_init(smx_context_factory_t *factory)
19 /* instantiate the context factory */
20 *factory = xbt_new0(s_smx_context_factory_t, 1);
22 (*factory)->create_context = NULL;
23 (*factory)->finalize = smx_ctx_base_factory_finalize;
24 (*factory)->free = smx_ctx_base_free;
25 (*factory)->stop = smx_ctx_base_stop;
26 (*factory)->suspend = NULL;
27 (*factory)->runall = NULL;
28 (*factory)->self = smx_ctx_base_self;
29 (*factory)->get_data = smx_ctx_base_get_data;
31 (*factory)->name = "base context factory";
34 int smx_ctx_base_factory_finalize(smx_context_factory_t * factory)
42 smx_ctx_base_factory_create_context_sized(size_t size,
43 xbt_main_func_t code, int argc,
45 void_pfn_smxprocess_t cleanup_func,
48 smx_context_t context = xbt_malloc0(size);
50 /* Store the address of the stack in heap to compare it apart of heap comparison */
52 MC_ignore(context, size);
54 /* If the user provided a function for the process then use it.
55 Otherwise, it is the context for maestro and we should set it as the
58 context->cleanup_func = cleanup_func;
63 SIMIX_context_set_current(context);
67 if(MC_IS_ENABLED && code)
68 MC_new_stack_area(context, ((smx_process_t)context->data)->name);
73 void smx_ctx_base_free(smx_context_t context)
80 for (i = 0; i < context->argc; i++)
81 free(context->argv[i]);
91 void smx_ctx_base_stop(smx_context_t context)
93 if (context->cleanup_func)
94 context->cleanup_func(context->data);
95 context->iwannadie = 0;
96 simcall_process_cleanup(context->data);
97 context->iwannadie = 1;
100 smx_context_t smx_ctx_base_self(void)
102 return SIMIX_context_get_current();
105 void *smx_ctx_base_get_data(smx_context_t context)
107 return context->data;