Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
In reality, Java use native thread synchronization. It will change, but for now,...
[simgrid.git] / src / xbt / context_private.h
index a2a8a9b..7778861 100644 (file)
 
 
 #include "xbt/sysdep.h"
+#include "xbt/swag.h"
+#include "xbt/dynar.h" /* void_f_pvoid_t */
+#include "portable.h"  /* loads context system definitions */
+
+#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32) && !defined(__TOS_WIN__)
+#include "ucontext_stack.h"  /* loads context system definitions */
+#endif
+
 #include "xbt/context.h"
-#include "portable.h" /* loads context system definitions */
-
-#define STACK_SIZE 524288
-typedef struct s_context {
-  ucontext_t uc;                /* the thread that execute the code   */
-  char stack[STACK_SIZE];
-  context_function_t code;        /* the scheduler fonction   */
-  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*/
-
-#endif              /* _XBT_CONTEXT_PRIVATE_H */
+#include "xbt/ex.h"
+
+#ifdef CONTEXT_THREADS
+#  include "xbt/xbt_thread.h"
+#else
+#  include <ucontext.h>
+#  define STACK_SIZE 128*1024 /* Lower this if you want to reduce the memory consumption */
+#endif     /* not CONTEXT_THREADS */
+
+
+typedef struct s_xbt_context {
+       s_xbt_swag_hookup_t hookup;
+
+       /* Declaration of the thread running the process */
+#ifdef JAVA_SIMGRID /* come first because other ones are defined too */
+       jobject jprocess;  /* the java process instance                 */
+       JNIEnv* jenv;      /* jni interface pointer for this thread     */
+#else   
+# ifdef CONTEXT_THREADS
+       xbt_thread_t thread; /* a plain dumb thread (portable to posix or windows) */
+# else
+       ucontext_t uc;       /* the thread that execute the code */
+       char stack[STACK_SIZE];
+       struct s_xbt_context *save;
+# endif /* CONTEXT_THREADS */
+#endif /* JAVA_SIMGRID */
+   
+       /* What we need to synchronize the process */        
+#if defined(JAVA_SIMGRID) || defined(CONTEXT_THREADS)
+       xbt_thcond_t cond;              /* the condition used to synchronize the process        */
+       xbt_mutex_t mutex;              /* the mutex used to synchronize the process            */
+#endif
+
+       /* What to run */
+       xbt_context_function_t code;    /* the scheduled fonction           */
+       int argc;
+       char **argv;
+   
+       /* Init/exit functions */   
+       void_f_pvoid_t *startup_func;
+       void *startup_arg;
+       void_f_pvoid_t *cleanup_func;
+       void *cleanup_arg;
+
+       ex_ctx_t *exception;            /* exception container    */
+       int iwannadie;                  /* Set to true by the context when it wants to commit suicide */
+
+   
+} s_xbt_context_t;
+
+
+#endif /* !_XBT_CONTEXT_PRIVATE_H */