/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include "private.h"
-//#include "context_sysv_config.h" /* loads context system definitions */
-//#include "portable.h"
-//#include <ucontext.h> /* context relative declarations */
+#include "smx_context_private.h"
#include <lua5.1/lauxlib.h>
#include <lua5.1/lualib.h>
}
void SIMIX_ctx_lua_factory_init(smx_context_factory_t *factory) {
- *factory = xbt_new0(s_smx_context_factory_t, 1);
+ smx_ctx_base_factory_init(factory);
(*factory)->create_context = smx_ctx_lua_create_context;
(*factory)->finalize = smx_ctx_lua_factory_finalize;
static int smx_ctx_lua_factory_finalize(smx_context_factory_t * factory) {
lua_close(lua_state);
- free(*factory);
- *factory = NULL;
- return 0;
+ return smx_ctx_base_factory_finalize(factory);
}
static smx_context_t
return (smx_context_t)context;
}
-static void smx_ctx_lua_free(smx_context_t pcontext)
-{
- int i;
- smx_ctx_lua_t context = (smx_ctx_lua_t)pcontext;
+static void smx_ctx_lua_free(smx_context_t context) {
if (context){
DEBUG1("smx_ctx_lua_free_context(%p)",context);
- /* free argv */
- if (context->super.argv) {
- for (i = 0; i < context->super.argc; i++)
- if (context->super.argv[i])
- free(context->super.argv[i]);
-
- free(context->super.argv);
- }
-
/* let the lua garbage collector reclaim the thread used for the coroutine */
- luaL_unref(lua_state,LUA_REGISTRYINDEX,context->ref );
-
- free(context);
- context = NULL;
+ luaL_unref(lua_state,LUA_REGISTRYINDEX,((smx_ctx_lua_t)context)->ref );
}
+
+ smx_ctx_base_free(context);
}
static void smx_ctx_lua_stop(smx_context_t pcontext) {