Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
proper use of the HAVE_TRACING variable defined by Cmake through -Dtracing=on
[simgrid.git] / src / simix / smx_context_lua.c
1 /* context_lua - implementation of context switching with lua coroutines */
2
3 /* Copyright (c) 2010 the SimGrid team. All right reserved */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include <lauxlib.h>
9 #include <lualib.h>
10
11 #include "smx_context_private.h"
12
13 /* We don't use that factory at all for now. This may change at some point,
14  * to reduce the amount of memory per user thread in sysv
15  */
16
17 lua_State *simgrid_lua_state;
18 void SIMIX_ctx_lua_factory_init(smx_context_factory_t *factory) {
19 }
20
21 #ifdef KILLME
22 /* lua can run with ultra tiny stacks since the user code lives in lua stacks, not the main one */
23 //#define CONTEXT_STACK_SIZE 4*1024
24
25 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(lua);
26
27
28 static smx_context_t 
29 smx_ctx_lua_create_context(xbt_main_func_t code, int argc, char** argv, 
30     void_f_pvoid_t cleanup_func, void* cleanup_arg);
31
32 static int smx_ctx_lua_factory_finalize(smx_context_factory_t *factory);
33
34 static void smx_ctx_lua_free(smx_context_t context);
35 static void smx_ctx_lua_stop(smx_context_t context);
36 static void smx_ctx_lua_suspend(smx_context_t context);
37 static void smx_ctx_lua_resume(smx_context_t new_context);
38
39
40 void SIMIX_ctx_lua_factory_init(smx_context_factory_t *factory) {
41
42   smx_ctx_base_factory_init(factory);
43
44   (*factory)->create_context = smx_ctx_lua_create_context;
45   /* don't override (*factory)->finalize */;
46   (*factory)->free = smx_ctx_sysv_free;
47   (*factory)->stop = smx_ctx_sysv_stop;
48   (*factory)->suspend = smx_ctx_sysv_suspend;
49   (*factory)->resume = smx_ctx_sysv_resume;
50   (*factory)->name = "smx_lua_context_factory";
51
52   INFO0("Lua Factory created");
53 }
54
55 static smx_context_t 
56 smx_ctx_lua_create_context(xbt_main_func_t code, int argc, char** argv, 
57     void_f_pvoid_t cleanup_func, void* cleanup_arg) {
58
59   return smx_ctx_sysv_create_context_sized(sizeof(s_smx_ctx_sysv_t),
60       code,argc,argv,cleanup_func,cleanup_arg);
61 }
62 #if KILLME
63 static void smx_ctx_lua_free(smx_context_t context) {
64
65   if (context){
66     DEBUG1("smx_ctx_lua_free_context(%p)",context);
67
68   }
69
70   smx_ctx_sysv_free(context);
71 }
72
73 static void smx_ctx_lua_stop(smx_context_t pcontext) {
74   DEBUG1("Stopping '%s' (nothing to do)",pcontext->argv[0]);
75   smx_ctx_sysv_stop(pcontext);
76 }
77
78 static void smx_ctx_lua_suspend(smx_context_t pcontext) {
79   smx_ctx_lua_t context = (smx_ctx_lua_t)pcontext;
80   DEBUG1("Suspending '%s' (using sysv facilities)",context->super.super.argv[0]);
81   smx_ctx_sysv_suspend(pcontext);
82
83   DEBUG0("Back from call yielding");
84 }
85
86 static void 
87 smx_ctx_lua_resume(smx_context_t new_context) {
88   smx_ctx_lua_t context = (smx_ctx_lua_t)new_context;
89   DEBUG1("Resuming %s",context->super.super.argv[0]);
90   smx_ctx_sysv_resume(new_context);
91 }
92 #endif
93
94 #endif