-static void smx_ctx_sysv_wrapper()
-{
- /*FIXME: I would like to avoid accesing simix_global to get the current
- context by passing it as an argument of the wrapper function. The problem
- is that this function is called from smx_ctx_sysv_start, and uses
- makecontext for calling it, and the stupid posix specification states that
- all the arguments of the function should be int(32 bits), making it useless
- in 64-bit architectures where pointers are 64 bit long.
- */
- smx_ctx_lua_t context =
- (smx_ctx_lua_t)simix_global->current_process->context;
-
- (context->code) (context->argc, context->argv);
-
- smx_ctx_lua_stop((smx_context_t)context);
-}
-
-
-static void smx_ctx_lua_suspend(smx_context_t context)
-{
- int rv;
- INFO1("Suspending %s",context->argv[0]);
- lua_yield(((smx_ctx_lua_t)context)->state,0); // Should be the last line of the function
- smx_ctx_lua_t prev_context = ((smx_ctx_lua_t) context)->prev;
-
- ((smx_ctx_lua_t) context)->prev = NULL;
-
- rv = swapcontext(&((smx_ctx_lua_t) context)->uc, &prev_context->uc);
-
- xbt_assert0((rv == 0), "Context swapping failure");
- // INFO1("Suspended %s",context->argv[0]);
+static void smx_ctx_lua_suspend(smx_context_t pcontext) {
+ smx_ctx_lua_t context = (smx_ctx_lua_t)pcontext;
+ DEBUG1("Suspending '%s' (calling lua_yield)",context->argv[0]);
+ //lua_yield(context->state,0);
+
+ lua_getglobal(context->state,"doyield");
+ xbt_assert0(lua_isfunction(context->state,-1),
+ "Cannot find the coroutine.yield function...");
+ INFO0("Call coroutine.yield");
+ lua_call(context->state,0,0);
+ INFO0("Back from call to coroutine.yield");