Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
context_t -> xbt_context_t
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 16 Dec 2004 00:56:14 +0000 (00:56 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 16 Dec 2004 00:56:14 +0000 (00:56 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@652 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/xbt/context.h
src/xbt/context.c
src/xbt/context_private.h

index 044325e..8e1c8ea 100644 (file)
@@ -8,14 +8,14 @@
 #ifndef _XBT_CONTEXT_H
 #define _XBT_CONTEXT_H
 
 #ifndef _XBT_CONTEXT_H
 #define _XBT_CONTEXT_H
 
-typedef struct s_context *context_t;
-typedef int(*context_function_t)(int argc, char *argv[]);
+typedef struct s_xbt_context *xbt_context_t;
+typedef int(*xbt_context_function_t)(int argc, char *argv[]);
 
 void context_init(void);
 void context_empty_trash(void);
 
 void context_init(void);
 void context_empty_trash(void);
-context_t context_create(context_function_t code, int argc, char *argv[]);
-void context_start(context_t context);
-void context_yield(context_t context);
-int context_get_id(context_t context);
+xbt_context_t context_create(xbt_context_function_t code, int argc, char *argv[]);
+void context_start(xbt_context_t context);
+void context_yield(xbt_context_t context);
+int context_get_id(xbt_context_t context);
 
 #endif                         /* _XBT_CONTEXT_H */
 
 #endif                         /* _XBT_CONTEXT_H */
index c7f59ed..91d60d0 100644 (file)
@@ -22,14 +22,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(context, xbt, "Context");
 # include "context_win32.c" 
 #endif
 
 # include "context_win32.c" 
 #endif
 
-static context_t current_context = NULL;
+static xbt_context_t current_context = NULL;
 static xbt_dynar_t context_to_destroy = NULL;
 
 void context_init(void)
 {
   if(!current_context) {
 static xbt_dynar_t context_to_destroy = NULL;
 
 void context_init(void)
 {
   if(!current_context) {
-    current_context = xbt_new0(s_context_t,1);
-    context_to_destroy = xbt_dynar_new(sizeof(context_t),xbt_free);
+    current_context = xbt_new0(s_xbt_context_t,1);
+    context_to_destroy = xbt_dynar_new(sizeof(xbt_context_t),xbt_free);
   }
 }
 
   }
 }
 
@@ -40,7 +40,7 @@ void context_empty_trash(void)
 
 static void *__context_wrapper(void *c)
 {
 
 static void *__context_wrapper(void *c)
 {
-  context_t context = c;
+  xbt_context_t context = c;
   int i;
 
 /*   msg_global->current_process = process; */
   int i;
 
 /*   msg_global->current_process = process; */
@@ -59,7 +59,7 @@ static void *__context_wrapper(void *c)
   return NULL;
 }
 
   return NULL;
 }
 
-void context_start(context_t context) 
+void context_start(xbt_context_t context) 
 {
 
 /*   TBX_FIFO_insert(msg_global->process, process); */
 {
 
 /*   TBX_FIFO_insert(msg_global->process, process); */
@@ -72,12 +72,12 @@ void context_start(context_t context)
   return;
 }
 
   return;
 }
 
-context_t context_create(context_function_t code,
+xbt_context_t context_create(xbt_context_function_t code,
                         int argc, char *argv[])
 {
                         int argc, char *argv[])
 {
-  context_t res = NULL;
+  xbt_context_t res = NULL;
 
 
-  res = xbt_new0(s_context_t,1);
+  res = xbt_new0(s_xbt_context_t,1);
 
   /*  WARNING("Initializing context (%p)",res); */
 
 
   /*  WARNING("Initializing context (%p)",res); */
 
@@ -93,14 +93,14 @@ context_t context_create(context_function_t code,
   return res;
 }
 
   return res;
 }
 
-static void context_destroy(context_t context)
+static void context_destroy(xbt_context_t context)
 {
   xbt_free(context);
 
   return;
 }
 
 {
   xbt_free(context);
 
   return;
 }
 
-void context_yield(context_t context)
+void context_yield(xbt_context_t context)
 {
 
   xbt_assert0(current_context,"You have to call context_init() first.");
 {
 
   xbt_assert0(current_context,"You have to call context_init() first.");
@@ -127,7 +127,7 @@ void context_yield(context_t context)
        xbt_assert0(0,"Context swapping failure");
       /*      WARNING("I am (%p). Coming back\n",context); */
     } else {
        xbt_assert0(0,"Context swapping failure");
       /*      WARNING("I am (%p). Coming back\n",context); */
     } else {
-      context_t old_context = context->save ;
+      xbt_context_t old_context = context->save ;
       /*      WARNING("**** Back ! ****"); */
       /*      WARNING("Setting current_context (%p) to context(%p)->save",current_context,context); */
       current_context = context->save ;
       /*      WARNING("**** Back ! ****"); */
       /*      WARNING("Setting current_context (%p) to context(%p)->save",current_context,context); */
       current_context = context->save ;
@@ -143,117 +143,3 @@ void context_yield(context_t context)
 
   return;
 }
 
   return;
 }
-
-
-/****************************** PTHREADS ***************************/
-
-/* FIXME: this is dead code as we don't really need it.
-   If you have pthreads, you have contexts (which are better) */
-
-#if 0 
-#ifdef HAVE_LIBPTHREAD  /* Nevermind, let's use pthreads... */
-
-static void *__MSG_process_launcher(void *p)
-{
-  m_process_t process = (m_process_t) p;
-  sim_data_process_t sim_data = process->simdata;
-  context_t context = NULL;
-  int i;
-  msg_global->current_process = process;
-  TBX_FIFO_insert(msg_global->process, process);
-
-  TBX_FIFO_insert(msg_global->process_to_run, process);
-/*   pthread_mutex_lock(&(sim_data->context->mutex)); */
-  __MSG_context_yield(sim_data->context);
-
-  (*sim_data->context->code) (sim_data->argc,sim_data->argv);
-
-  TBX_FIFO_remove(msg_global->process, process);
-  TBX_FIFO_remove(msg_global->process_to_run, process);
-
-  /* Free blocked process if any */
-/*   pthread_mutex_lock(&(sim_data->context->mutex)); */
-/*   pthread_cond_signal(&(sim_data->context->cond)); */
-/*   pthread_mutex_unlock(&(sim_data->context->mutex)); */
-
-  context = sim_data->context;
-
-  for(i=0;i<sim_data->argc; i++) 
-    if(sim_data->argv[i]) FREE(sim_data->argv[i]);
-  if(sim_data->argv) FREE(sim_data->argv);
-  if(process->name) FREE(process->name);
-  FREE(sim_data);
-  FREE(process);
-
-  TBX_FIFO_insert(msg_global->context_to_destroy,context);
-  __MSG_context_yield(context);
-/*   __MSG_context_destroy(&context); */
-
-  return NULL;
-}
-
-MSG_error_t __MSG_context_start(m_process_t process) 
-{
-  sim_data_process_t sim_data = NULL;
-
-  sim_data = process->simdata;
-
-  pthread_mutex_lock(&(sim_data->context->mutex));
-
-  /* Launch the thread */
-  if (pthread_create(sim_data->context->thread, NULL, __MSG_process_launcher,
-                    process) != 0) {
-    WARNING("Unable to create a thread.");
-    return MSG_FATAL;
-  }
-  pthread_cond_wait(&(sim_data->context->cond), &(sim_data->context->mutex));
-  pthread_mutex_unlock(&(sim_data->context->mutex));
-/*   __MSG_context_yield(sim_data->context); */
-
-  return MSG_OK;
-}
-
-context_t __MSG_context_create(m_process_code_t code)
-{
-  context_t res = NULL;
-
-  res = CALLOC(1, sizeof(struct s_context));
-
-  res->code = code;
-  res->thread = CALLOC(1, sizeof(pthread_t));
-  if (pthread_mutex_init(&(res->mutex), NULL) != 0)
-    FAILURE("Mutex initialization error");
-  if (pthread_cond_init(&(res->cond), NULL) != 0)
-    FAILURE("Condition initialization error");
-
-  return res;
-}
-
-MSG_error_t __MSG_context_destroy(context_t * context)
-{
-  ASSERT(((context != NULL) && (*context != NULL)), "Invalid parameters");
-
-  FREE((*context)->thread);
-  pthread_mutex_destroy(&((*context)->mutex));
-  pthread_cond_destroy(&((*context)->cond));
-
-  FREE(*context);
-  *context = NULL;
-
-  return MSG_OK;
-}
-
-MSG_error_t __MSG_context_yield(context_t context)
-{
-  if (context) {
-    m_process_t self = msg_global->current_process;
-    pthread_mutex_lock(&(context->mutex));
-    pthread_cond_signal(&context->cond);
-    pthread_cond_wait(&context->cond, &context->mutex);
-    pthread_mutex_unlock(&(context->mutex));
-    msg_global->current_process = self;
-  }
-  return MSG_OK;
-}
-#endif /* HAVE_LIBPTHREAD */
-#endif /* 0 */
index a2a8a9b..90caf13 100644 (file)
 #include "portable.h" /* loads context system definitions */
 
 #define STACK_SIZE 524288
 #include "portable.h" /* loads context system definitions */
 
 #define STACK_SIZE 524288
-typedef struct s_context {
+typedef struct s_xbt_context {
   ucontext_t uc;                /* the thread that execute the code   */
   char stack[STACK_SIZE];
   ucontext_t uc;                /* the thread that execute the code   */
   char stack[STACK_SIZE];
-  context_function_t code;        /* the scheduler fonction   */
+  xbt_context_function_t code;        /* the scheduler fonction   */
   int argc;
   char **argv;
   int argc;
   char **argv;
-  struct s_context *save;
-} s_context_t;
-
-
-#if 0 /* FIXME: KILLME */
-//#ifdef HAVE_LIBPTHREAD
-#include <pthread.h>
-typedef struct s_context {
-  pthread_cond_t cond;
-  pthread_mutex_t mutex;
-  pthread_t *thread;            /* the thread that execute the code   */
-  context_function_t code;                /* the scheduler fonction   */
-  int argc;
-  char *argv[];
-} s_context_t;
-#endif /* ENDOFKILLME*/
+  struct s_xbt_context *save;
+} s_xbt_context_t;
 
 #endif              /* _XBT_CONTEXT_PRIVATE_H */
 
 #endif              /* _XBT_CONTEXT_PRIVATE_H */