xbt_context_t context = NULL;
xbt_pfn_context_factory_finalize_t finalize_factory;
- /* finalize the context factory */
- finalize_factory = context_factory->finalize;
-
- (*finalize_factory) (&context_factory);
-
/* destroy all contexts in the list of contexts to destroy */
xbt_context_empty_trash();
* the killed contexts are added in the list of the contexts to destroy
*/
while ((context = xbt_swag_extract(context_living)))
- (*(context->kill)) (context);
-
+ (*(context_factory->kill)) (context);
/* destroy all contexts in the list of contexts to destroy */
xbt_context_empty_trash();
+ /* finalize the context factory */
+ finalize_factory = context_factory->finalize;
+
+ (*finalize_factory) (&context_factory);
+
free(maestro_context);
maestro_context = current_context = NULL;
/* destroy the lists */
- xbt_swag_free(context_to_destroy);
+ xbt_swag_free(context_to_destroy);
xbt_swag_free(context_living);
}
}
/* Argument must be stopped first -- runs in maestro context */
void xbt_context_free(xbt_context_t context)
{
- (*(context->free)) (context);
+ (*(context_factory->free)) (context);
}
void xbt_context_kill(xbt_context_t context)
{
- (*(context->kill)) (context);
+ (*(context_factory->kill)) (context);
}
/**
*/
void xbt_context_start(xbt_context_t context)
{
- (*(context->start)) (context);
+ (*(context_factory->start)) (context);
}
/**
*/
void xbt_context_yield(void)
{
- (*(current_context->yield)) ();
+ (*(context_factory->yield)) ();
}
/**
*/
void xbt_context_schedule(xbt_context_t context)
{
- (*(context->schedule)) (context);
+ (*(context_factory->schedule)) (context);
}
void xbt_context_stop(int exit_code)
{
- (*(current_context->stop)) (exit_code);
+ (*(context_factory->stop)) (exit_code);
}
int xbt_context_select_factory(const char *name)
#endif /* CONTEXT_THREADS */
else if (!strcmp(name, "sysv"))
-#ifndef WIN32
+#if !defined(WIN32) && !defined(CONTEXT_THREADS)
xbt_ctx_sysv_factory_init(factory);
#else
THROW0(not_found_error, 0, "Factory 'sysv' does not exist: no System V thread support under Windows");
-#endif
-
+#endif
else
THROW1(not_found_error, 0, "Factory '%s' does not exist", name);
-
}
/** Garbage collection
xbt_context_t context = NULL;
while ((context = xbt_swag_extract(context_to_destroy)))
- (*(context->free)) (context);
+ (*(context_factory->free)) (context);
}
(*factory)->create_context = xbt_ctx_java_factory_create_context;
(*factory)->finalize = xbt_ctx_java_factory_finalize;
- (*factory)->create_maestro_context =
- xbt_ctx_java_factory_create_maestro_context;
+ (*factory)->create_maestro_context = xbt_ctx_java_factory_create_maestro_context;
+ (*factory)->free = xbt_ctx_java_free;
+ (*factory)->kill = xbt_ctx_java_kill;
+ (*factory)->schedule = xbt_ctx_java_schedule;
+ (*factory)->yield = xbt_ctx_java_yield;
+ (*factory)->start = xbt_ctx_java_start;
+ (*factory)->stop = xbt_ctx_java_stop;
(*factory)->name = "ctx_java_factory";
}
xbt_ctx_java_t context = xbt_new0(s_xbt_ctx_java_t, 1);
context->name = xbt_strdup(name);
-
context->cleanup_func = cleanup_func;
context->cleanup_arg = cleanup_arg;
-
context->exception = xbt_new(ex_ctx_t, 1);
XBT_CTX_INITIALIZE(context->exception);
-
- context->free = xbt_ctx_java_free;
- context->kill = xbt_ctx_java_kill;
- context->schedule = xbt_ctx_java_schedule;
- context->yield = xbt_ctx_java_yield;
- context->start = xbt_ctx_java_start;
- context->stop = xbt_ctx_java_stop;
context->jprocess = (jobject) startup_arg;
context->jenv = get_current_thread_env();
/* the following function pointers types describe the interface that all context
concepts must implement */
-typedef void (*xbt_pfn_context_free_t) (xbt_context_t); /* function used to destroy the specified context */
-
-typedef void (*xbt_pfn_context_kill_t) (xbt_context_t); /* function used to kill the specified context */
-
-typedef void (*xbt_pfn_context_schedule_t) (xbt_context_t); /* function used to resume the specified context */
-
-typedef void (*xbt_pfn_context_yield_t) (void); /* function used to yield the specified context */
-
-typedef void (*xbt_pfn_context_start_t) (xbt_context_t); /* function used to start the specified context */
-
-typedef void (*xbt_pfn_context_stop_t) (int); /* function used to stop the current context */
-
/* each context type must contain this macro at its begining -- OOP in C :/ */
#define XBT_CTX_BASE_T \
s_xbt_swag_hookup_t hookup; \
int argc; \
char **argv; \
void_f_pvoid_t startup_func; \
- void *startup_arg; \
- xbt_pfn_context_free_t free; \
- xbt_pfn_context_kill_t kill; \
- xbt_pfn_context_schedule_t schedule; \
- xbt_pfn_context_yield_t yield; \
- xbt_pfn_context_start_t start; \
- xbt_pfn_context_stop_t stop
+ void *startup_arg;
/* all other context types derive from this structure */
typedef struct s_xbt_context {
/* this function finalize the specified context factory */
typedef int (*xbt_pfn_context_factory_finalize_t) (xbt_context_factory_t*);
+/* function used to destroy the specified context */
+typedef void (*xbt_pfn_context_free_t) (xbt_context_t);
+
+/* function used to kill the specified context */
+typedef void (*xbt_pfn_context_kill_t) (xbt_context_t);
+
+/* function used to resume the specified context */
+typedef void (*xbt_pfn_context_schedule_t) (xbt_context_t);
+
+/* function used to yield the specified context */
+typedef void (*xbt_pfn_context_yield_t) (void);
+
+/* function used to start the specified context */
+typedef void (*xbt_pfn_context_start_t) (xbt_context_t);
+
+/* function used to stop the current context */
+typedef void (*xbt_pfn_context_stop_t) (int);
+
/* interface of the context factories */
typedef struct s_xbt_context_factory {
xbt_pfn_context_factory_create_maestro_context_t create_maestro_context;
xbt_pfn_context_factory_create_context_t create_context;
xbt_pfn_context_factory_finalize_t finalize;
+ xbt_pfn_context_free_t free;
+ xbt_pfn_context_kill_t kill;
+ xbt_pfn_context_schedule_t schedule;
+ xbt_pfn_context_yield_t yield;
+ xbt_pfn_context_start_t start;
+ xbt_pfn_context_stop_t stop;
const char *name;
} s_xbt_context_factory_t;
void xbt_ctx_sysv_factory_init(xbt_context_factory_t * factory)
{
- /* context exception */
*factory = xbt_new0(s_xbt_context_factory_t, 1);
(*factory)->create_context = xbt_ctx_sysv_factory_create_context;
(*factory)->finalize = xbt_ctx_sysv_factory_finalize;
- (*factory)->create_maestro_context =
- xbt_ctx_sysv_factory_create_maestro_context;
+ (*factory)->create_maestro_context = xbt_ctx_sysv_factory_create_maestro_context;
+ (*factory)->free = xbt_ctx_sysv_free;
+ (*factory)->kill = xbt_ctx_sysv_kill;
+ (*factory)->schedule = xbt_ctx_sysv_schedule;
+ (*factory)->yield = xbt_ctx_sysv_yield;
+ (*factory)->start = xbt_ctx_sysv_start;
+ (*factory)->stop = xbt_ctx_sysv_stop;
(*factory)->name = "ctx_sysv_context_factory";
/* context exception handlers */
context->cleanup_func = cleanup_func;
context->cleanup_arg = cleanup_arg;
-
- context->free = xbt_ctx_sysv_free;
- context->kill = xbt_ctx_sysv_kill;
- context->schedule = xbt_ctx_sysv_schedule;
- context->yield = xbt_ctx_sysv_yield;
- context->start = xbt_ctx_sysv_start;
- context->stop = xbt_ctx_sysv_stop;
-
return (xbt_context_t) context;
}
current_context = context;
- rv =
- swapcontext(&(((xbt_ctx_sysv_t) context)->prev->uc),
- &(((xbt_ctx_sysv_t) context)->uc));
+ rv = swapcontext(&(((xbt_ctx_sysv_t) context)->prev->uc),
+ &(((xbt_ctx_sysv_t) context)->uc));
xbt_assert0((rv == 0), "Context swapping failure");
}
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "xbt/function_types.h"
-#include "xbt/xbt_context_private.h"
+#include "xbt_context_private.h"
#include "portable.h" /* loads context system definitions */
#include "xbt/swag.h"
(*factory)->create_context = xbt_ctx_thread_factory_create_context;
(*factory)->finalize = xbt_ctx_thread_factory_finalize;
- (*factory)->create_maestro_context =
- xbt_ctx_thread_factory_create_master_context;
+ (*factory)->create_maestro_context = xbt_ctx_thread_factory_create_master_context;
+ (*factory)->free = xbt_ctx_thread_free;
+ (*factory)->kill = xbt_ctx_thread_kill;
+ (*factory)->schedule = xbt_ctx_thread_schedule;
+ (*factory)->yield = xbt_ctx_thread_yield;
+ (*factory)->start = xbt_ctx_thread_start;
+ (*factory)->stop = xbt_ctx_thread_stop;
(*factory)->name = "ctx_thread_factory";
}
context->cleanup_func = cleanup_func;
context->cleanup_arg = cleanup_arg;
- context->free = xbt_ctx_thread_free;
- context->kill = xbt_ctx_thread_kill;
- context->schedule = xbt_ctx_thread_schedule;
- context->yield = xbt_ctx_thread_yield;
- context->start = xbt_ctx_thread_start;
- context->stop = xbt_ctx_thread_stop;
-
return (xbt_context_t) context;
}