\r
#include "xbt/function_types.h"\r
-#include "xbt/xbt_context_factory.h"\r
+#include "xbt/xbt_context_private.h"\r
\r
#include "portable.h" /* loads context system definitions */\r
#include "xbt/swag.h"\r
#include "xbt/xbt_os_thread.h"\r
\r
\r
-typedef struct s_xbt_thread_context {\r
+typedef struct s_xbt_ctx_thread {\r
XBT_CTX_BASE_T;\r
xbt_os_thread_t thread; /* a plain dumb thread (portable to posix or windows) */\r
xbt_os_sem_t begin; /* this semaphore is used to schedule/yield the process */\r
xbt_os_sem_t end; /* this semaphore is used to schedule/unschedule the process */\r
-} s_xbt_thread_context_t,* xbt_thread_context_t;\r
+} s_xbt_ctx_thread_t,* xbt_ctx_thread_t;\r
\r
static xbt_context_t \r
-xbt_thread_context_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv);\r
+xbt_ctx_thread_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv);\r
\r
\r
static int\r
-xbt_thread_context_factory_create_master_context(xbt_context_t* maestro);\r
+xbt_ctx_thread_factory_create_master_context(xbt_context_t* maestro);\r
\r
static int\r
-xbt_thread_context_factory_finalize(xbt_context_factory_t* factory);\r
+xbt_ctx_thread_factory_finalize(xbt_context_factory_t* factory);\r
\r
static void \r
-xbt_thread_context_free(xbt_context_t context);\r
+xbt_ctx_thread_free(xbt_context_t context);\r
\r
static void \r
-xbt_thread_context_kill(xbt_context_t context);\r
+xbt_ctx_thread_kill(xbt_context_t context);\r
\r
static void \r
-xbt_thread_context_schedule(xbt_context_t context);\r
+xbt_ctx_thread_schedule(xbt_context_t context);\r
\r
static void \r
-xbt_thread_context_yield(void);\r
+xbt_ctx_thread_yield(void);\r
\r
static void \r
-xbt_thread_context_start(xbt_context_t context);\r
+xbt_ctx_thread_start(xbt_context_t context);\r
\r
static void \r
-xbt_thread_context_stop(int exit_code);\r
+xbt_ctx_thread_stop(int exit_code);\r
\r
static void \r
-xbt_thread_context_swap(xbt_context_t context);\r
+xbt_ctx_thread_swap(xbt_context_t context);\r
\r
static void\r
-xbt_thread_context_schedule(xbt_context_t context);\r
+xbt_ctx_thread_schedule(xbt_context_t context);\r
\r
static void\r
-xbt_thread_context_yield(void);\r
+xbt_ctx_thread_yield(void);\r
\r
static void\r
-xbt_thread_context_suspend(xbt_context_t context);\r
+xbt_ctx_thread_suspend(xbt_context_t context);\r
\r
static void\r
-xbt_thread_context_resume(xbt_context_t context);\r
+xbt_ctx_thread_resume(xbt_context_t context);\r
\r
static void* \r
-xbt_thread_context_wrapper(void* param);\r
+xbt_ctx_thread_wrapper(void* param);\r
\r
int\r
-xbt_thread_context_factory_init(xbt_context_factory_t* factory)\r
+xbt_ctx_thread_factory_init(xbt_context_factory_t* factory)\r
{\r
*factory = xbt_new0(s_xbt_context_factory_t,1);\r
\r
- (*factory)->create_context = xbt_thread_context_factory_create_context;\r
- (*factory)->finalize = xbt_thread_context_factory_finalize;\r
- (*factory)->create_maestro_context = xbt_thread_context_factory_create_master_context;\r
- (*factory)->name = "thread_context_factory";\r
+ (*factory)->create_context = xbt_ctx_thread_factory_create_context;\r
+ (*factory)->finalize = xbt_ctx_thread_factory_finalize;\r
+ (*factory)->create_maestro_context = xbt_ctx_thread_factory_create_master_context;\r
+ (*factory)->name = "ctx_thread_factory";\r
\r
return 0;\r
}\r
\r
static int\r
-xbt_thread_context_factory_create_master_context(xbt_context_t* maestro)\r
+xbt_ctx_thread_factory_create_master_context(xbt_context_t* maestro)\r
{\r
- *maestro = (xbt_context_t)xbt_new0(s_xbt_thread_context_t, 1);\r
+ *maestro = (xbt_context_t)xbt_new0(s_xbt_ctx_thread_t, 1);\r
return 0;\r
}\r
\r
static int\r
-xbt_thread_context_factory_finalize(xbt_context_factory_t* factory)\r
+xbt_ctx_thread_factory_finalize(xbt_context_factory_t* factory)\r
{\r
free(*factory);\r
*factory = NULL;\r
}\r
\r
static xbt_context_t \r
-xbt_thread_context_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv)\r
+xbt_ctx_thread_factory_create_context(const char* name, xbt_main_func_t code, void_f_pvoid_t startup_func, void* startup_arg, void_f_pvoid_t cleanup_func, void* cleanup_arg, int argc, char** argv)\r
{\r
- xbt_thread_context_t context = xbt_new0(s_xbt_thread_context_t, 1);\r
+ xbt_ctx_thread_t context = xbt_new0(s_xbt_ctx_thread_t, 1);\r
\r
context->code = code;\r
context->name = xbt_strdup(name);\r
context->cleanup_func = cleanup_func;\r
context->cleanup_arg = cleanup_arg;\r
\r
- context->free = xbt_thread_context_free; \r
- context->kill = xbt_thread_context_kill; \r
- context->schedule = xbt_thread_context_schedule;\r
- context->yield = xbt_thread_context_yield; \r
- context->start = xbt_thread_context_start; \r
- context->stop = xbt_thread_context_stop; \r
+ context->free = xbt_ctx_thread_free; \r
+ context->kill = xbt_ctx_thread_kill; \r
+ context->schedule = xbt_ctx_thread_schedule;\r
+ context->yield = xbt_ctx_thread_yield; \r
+ context->start = xbt_ctx_thread_start; \r
+ context->stop = xbt_ctx_thread_stop; \r
\r
return (xbt_context_t)context;\r
}\r
\r
static void \r
-xbt_thread_context_free(xbt_context_t context)\r
+xbt_ctx_thread_free(xbt_context_t context)\r
{\r
if(context)\r
{\r
- xbt_thread_context_t thread_context = (xbt_thread_context_t)context;\r
+ xbt_ctx_thread_t ctx_thread = (xbt_ctx_thread_t)context;\r
\r
- free(thread_context->name);\r
+ free(ctx_thread->name);\r
\r
- if(thread_context->argv)\r
+ if(ctx_thread->argv)\r
{\r
int i;\r
\r
- for(i = 0; i < thread_context->argc; i++)\r
- if(thread_context->argv[i])\r
- free(thread_context->argv[i]);\r
+ for(i = 0; i < ctx_thread->argc; i++)\r
+ if(ctx_thread->argv[i])\r
+ free(ctx_thread->argv[i]);\r
\r
- free(thread_context->argv);\r
+ free(ctx_thread->argv);\r
}\r
\r
/* wait about the thread terminason */\r
- xbt_os_thread_join(thread_context->thread, NULL);\r
+ xbt_os_thread_join(ctx_thread->thread, NULL);\r
\r
/* destroy the synchronisation objects */\r
- xbt_os_sem_destroy(thread_context->begin);\r
- xbt_os_sem_destroy(thread_context->end);\r
+ xbt_os_sem_destroy(ctx_thread->begin);\r
+ xbt_os_sem_destroy(ctx_thread->end);\r
\r
/* finally destroy the context */\r
free(context);\r
}\r
\r
static void \r
-xbt_thread_context_kill(xbt_context_t context)\r
+xbt_ctx_thread_kill(xbt_context_t context)\r
{\r
context->iwannadie = 1;\r
- xbt_thread_context_swap(context);\r
+ xbt_ctx_thread_swap(context);\r
}\r
\r
/** \r
* Only the maestro can call this function to run a given process.\r
*/\r
static void \r
-xbt_thread_context_schedule(xbt_context_t context)\r
+xbt_ctx_thread_schedule(xbt_context_t context)\r
{\r
xbt_assert0((current_context == maestro_context),"You are not supposed to run this function here!");\r
- xbt_thread_context_swap(context);\r
+ xbt_ctx_thread_swap(context);\r
}\r
\r
/** \r
* to the maestro\r
*/\r
static void \r
-xbt_thread_context_yield(void)\r
+xbt_ctx_thread_yield(void)\r
{\r
xbt_assert0((current_context != maestro_context),"You are not supposed to run this function here!");\r
- xbt_thread_context_swap(current_context);\r
+ xbt_ctx_thread_swap(current_context);\r
}\r
\r
static void \r
-xbt_thread_context_start(xbt_context_t context)\r
+xbt_ctx_thread_start(xbt_context_t context)\r
{\r
- xbt_thread_context_t thread_context = (xbt_thread_context_t)context;\r
+ xbt_ctx_thread_t ctx_thread = (xbt_ctx_thread_t)context;\r
\r
/* create and start the process */\r
- thread_context->thread = xbt_os_thread_create(thread_context->name,xbt_thread_context_wrapper,thread_context);\r
+ ctx_thread->thread = xbt_os_thread_create(ctx_thread->name,xbt_ctx_thread_wrapper,ctx_thread);\r
\r
/* wait the starting of the newly created process */\r
- xbt_os_sem_acquire(thread_context->end);\r
+ xbt_os_sem_acquire(ctx_thread->end);\r
}\r
\r
static void \r
-xbt_thread_context_stop(int exit_code)\r
+xbt_ctx_thread_stop(int exit_code)\r
{\r
if(current_context->cleanup_func) \r
((*current_context->cleanup_func))(current_context->cleanup_arg);\r
xbt_swag_insert(current_context, context_to_destroy); \r
\r
/* signal to the maestro that it has finished */\r
- xbt_os_sem_release(((xbt_thread_context_t)current_context)->end);\r
+ xbt_os_sem_release(((xbt_ctx_thread_t)current_context)->end);\r
\r
/* exit*/\r
xbt_os_thread_exit(NULL); /* We should provide return value in case other wants it */\r
}\r
\r
static void \r
-xbt_thread_context_swap(xbt_context_t context)\r
+xbt_ctx_thread_swap(xbt_context_t context)\r
{\r
if((current_context != maestro_context) && !context->iwannadie)\r
{\r
/* (0) it's not the scheduler and the process doesn't want to die, it just wants to yield */\r
\r
/* yield itself, resume the maestro */\r
- xbt_thread_context_suspend(context);\r
+ xbt_ctx_thread_suspend(context);\r
}\r
else\r
{\r
* -> goto (3.1)\r
*/\r
/* schedule the process associated with this context */\r
- xbt_thread_context_resume(context);\r
+ xbt_ctx_thread_resume(context);\r
\r
}\r
\r
/* (4) the current process wants to die */\r
if(current_context->iwannadie)\r
- xbt_thread_context_stop(1);\r
+ xbt_ctx_thread_stop(1);\r
}\r
\r
static void* \r
-xbt_thread_context_wrapper(void* param)\r
+xbt_ctx_thread_wrapper(void* param)\r
{\r
- xbt_thread_context_t context = (xbt_thread_context_t)param;\r
+ xbt_ctx_thread_t context = (xbt_ctx_thread_t)param;\r
\r
/* Tell the maestro we are starting, and wait for its green light */\r
xbt_os_sem_release(context->end); \r
(*(context->startup_func))(context->startup_arg);\r
\r
\r
- xbt_thread_context_stop((context->code) (context->argc, context->argv));\r
+ xbt_ctx_thread_stop((context->code) (context->argc, context->argv));\r
return NULL;\r
}\r
\r
static void\r
-xbt_thread_context_suspend(xbt_context_t context)\r
+xbt_ctx_thread_suspend(xbt_context_t context)\r
{\r
/* save the current context */\r
xbt_context_t self = current_context;\r
/* update the current context to this context */\r
current_context = context;\r
\r
- xbt_os_sem_release(((xbt_thread_context_t)context)->end); \r
- xbt_os_sem_acquire(((xbt_thread_context_t)context)->begin);\r
+ xbt_os_sem_release(((xbt_ctx_thread_t)context)->end); \r
+ xbt_os_sem_acquire(((xbt_ctx_thread_t)context)->begin);\r
\r
/* restore the current context to the previously saved context */\r
current_context = self; \r
}\r
\r
static void\r
-xbt_thread_context_resume(xbt_context_t context)\r
+xbt_ctx_thread_resume(xbt_context_t context)\r
{\r
/* save the current context */\r
xbt_context_t self = current_context;\r
/* update the current context */\r
current_context = context;\r
\r
- xbt_os_sem_release(((xbt_thread_context_t)context)->begin); \r
- xbt_os_sem_acquire(((xbt_thread_context_t)context)->end);\r
+ xbt_os_sem_release(((xbt_ctx_thread_t)context)->begin); \r
+ xbt_os_sem_acquire(((xbt_ctx_thread_t)context)->end);\r
\r
/* restore the current context to the previously saved context */\r
current_context = self;\r