Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename xbt_thread, xbt_mutex and xbt_thcond to xbt_os_thread, xbt_os_mutex and xbt_os...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 9 Jul 2007 16:32:07 +0000 (16:32 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 9 Jul 2007 16:32:07 +0000 (16:32 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3696 48e7efb5-ca39-0410-a469-dd3cf9ba447f

13 files changed:
src/Makefile.am
src/Makefile.in
src/gras_config.h.in
src/include/xbt/xbt_os_thread.h [new file with mode: 0644]
src/include/xbt/xbt_thread.h [deleted file]
src/java/jmsg.c
src/java/jxbt_context.c
src/java/jxbt_context.h
src/xbt/context.c
src/xbt/context_private.h
src/xbt/xbt_main.c
src/xbt/xbt_os_thread.c [moved from src/xbt/xbt_thread.c with 77% similarity]
src/xbt_modinter.h

index f7a5c5d..08bec14 100644 (file)
@@ -49,7 +49,7 @@ EXTRA_DIST= \
        include/surf/surfxml_parse_private.h \
        \
        include/xbt/xbt_portability.h \
-       include/xbt/xbt_thread.h \
+       include/xbt/xbt_os_thread.h \
        include/xbt/context.h \
        \
        msg/private.h \
@@ -152,7 +152,7 @@ GTNETS_SRC= \
 
 # Separated because we don't want it in libsimgrid4java
 CTX_SRC= xbt/context.c
-JCTX_SRC= java/jxbt_context.c java/jxbt_context.h xbt/xbt_thread.c
+JCTX_SRC= java/jxbt_context.c java/jxbt_context.h xbt/xbt_os_thread.c
 
 SIMIX_SRC= \
   simix/smx_global.c \
@@ -209,7 +209,7 @@ GRAS_COMMON_SRC= \
   gras/DataDesc/ddt_parse.c           gras/DataDesc/ddt_parse.yy.c         gras/DataDesc/ddt_parse.yy.h
 
 GRAS_RL_SRC= \
-  gras/rl_stubs.c                     xbt/xbt_thread.c                    \
+  gras/rl_stubs.c                     xbt/xbt_os_thread.c                    \
   \
   gras/Transport/rl_transport.c          \
   gras/Transport/transport_plugin_file.c   gras/Transport/transport_plugin_tcp.c  \
@@ -226,7 +226,6 @@ GRAS_SG_SRC= gras/Transport/sg_transport.c  gras/Transport/transport_plugin_sg.c
   gras/Virtu/sg_process.c        gras/Virtu/sg_time.c     \
   gras/Virtu/sg_dns.c\
   \
-  gras/sg_stubs.c                         \
   gras/Msg/sg_msg.c
 
 AMOK_SRC= \
index c97217e..6d6b956 100644 (file)
@@ -85,7 +85,7 @@ am__objects_1 = snprintf.lo xbt_str.lo ex.lo xbt_virtu.lo sysdep.lo \
 am__objects_2 = gras.lo transport.lo msg.lo rpc.lo timer.lo process.lo \
        gras_module.lo ddt_create.lo ddt_convert.lo ddt_exchange.lo \
        cbps.lo datadesc.lo ddt_parse.lo ddt_parse.yy.lo
-am__objects_3 = rl_stubs.lo xbt_thread.lo rl_transport.lo \
+am__objects_3 = rl_stubs.lo xbt_os_thread.lo rl_transport.lo \
        transport_plugin_file.lo transport_plugin_tcp.lo rl_emul.lo \
        rl_process.lo rl_time.lo rl_dns.lo rl_msg.lo
 am__objects_4 = amok_base.lo bandwidth.lo saturate.lo \
@@ -130,9 +130,9 @@ am__libsimgrid_la_SOURCES_DIST = xbt/snprintf.c xbt/xbt_str.c xbt/ex.c \
        gras/Transport/sg_transport.c \
        gras/Transport/transport_plugin_sg.c gras/Virtu/sg_emul.c \
        gras/Virtu/sg_process.c gras/Virtu/sg_time.c \
-       gras/Virtu/sg_dns.c gras/sg_stubs.c gras/Msg/sg_msg.c \
-       amok/amok_base.c amok/Bandwidth/bandwidth.c \
-       amok/Bandwidth/saturate.c amok/PeerManagement/peermanagement.c
+       gras/Virtu/sg_dns.c gras/Msg/sg_msg.c amok/amok_base.c \
+       amok/Bandwidth/bandwidth.c amok/Bandwidth/saturate.c \
+       amok/PeerManagement/peermanagement.c
 am__objects_5 = maxmin.lo lagrange.lo trace_mgr.lo surf.lo \
        surfxml_parse.lo cpu.lo network.lo workstation.lo \
        surf_timer.lo network_dassf.lo workstation_KCCFLN05.lo
@@ -148,7 +148,7 @@ am__objects_11 = msg_config.lo task.lo host.lo m_process.lo gos.lo \
        global.lo environment.lo deployment.lo
 am__objects_12 = sd_global.lo sd_link.lo sd_task.lo sd_workstation.lo
 am__objects_13 = sg_transport.lo transport_plugin_sg.lo sg_emul.lo \
-       sg_process.lo sg_time.lo sg_dns.lo sg_stubs.lo sg_msg.lo
+       sg_process.lo sg_time.lo sg_dns.lo sg_msg.lo
 am_libsimgrid_la_OBJECTS = $(am__objects_1) $(am__objects_5) \
        $(am__objects_7) $(am__objects_8) $(am__objects_9) \
        $(am__objects_10) $(am__objects_11) $(am__objects_12) \
@@ -175,7 +175,7 @@ am__libsimgrid4java_la_SOURCES_DIST = xbt/snprintf.c xbt/xbt_str.c \
        surf/sdp.c simix/smx_global.c simix/smx_deployment.c \
        simix/smx_config.c simix/smx_environment.c simix/smx_host.c \
        simix/smx_process.c simix/smx_action.c simix/smx_synchro.c \
-       java/jxbt_context.c java/jxbt_context.h xbt/xbt_thread.c \
+       java/jxbt_context.c java/jxbt_context.h xbt/xbt_os_thread.c \
        java/jxbt_utilities.c java/jxbt_utilities.h java/jmsg.c \
        java/jmsg.h java/jmsg_channel.c java/jmsg_channel.h \
        java/jmsg_host.c java/jmsg_host.h java/jmsg_parallel_task.c \
@@ -196,10 +196,10 @@ am__libsimgrid4java_la_SOURCES_DIST = xbt/snprintf.c xbt/xbt_str.c \
        gras/Transport/sg_transport.c \
        gras/Transport/transport_plugin_sg.c gras/Virtu/sg_emul.c \
        gras/Virtu/sg_process.c gras/Virtu/sg_time.c \
-       gras/Virtu/sg_dns.c gras/sg_stubs.c gras/Msg/sg_msg.c \
-       amok/amok_base.c amok/Bandwidth/bandwidth.c \
-       amok/Bandwidth/saturate.c amok/PeerManagement/peermanagement.c
-am__objects_14 = jxbt_context.lo xbt_thread.lo
+       gras/Virtu/sg_dns.c gras/Msg/sg_msg.c amok/amok_base.c \
+       amok/Bandwidth/bandwidth.c amok/Bandwidth/saturate.c \
+       amok/PeerManagement/peermanagement.c
+am__objects_14 = jxbt_context.lo xbt_os_thread.lo
 am__objects_15 = jxbt_utilities.lo jmsg.lo jmsg_channel.lo \
        jmsg_host.lo jmsg_parallel_task.lo jmsg_process.lo \
        jmsg_task.lo
@@ -418,7 +418,7 @@ EXTRA_DIST = portable.h xbt/mallocator_private.h xbt/dynar_private.h \
        surf/workstation_KCCFLN05_private.h include/surf/maxmin.h \
        include/surf/trace_mgr.h include/surf/surf.h \
        include/surf/surfxml_parse_private.h \
-       include/xbt/xbt_portability.h include/xbt/xbt_thread.h \
+       include/xbt/xbt_portability.h include/xbt/xbt_os_thread.h \
        include/xbt/context.h msg/private.h simdag/private.h \
        amok/Bandwidth/bandwidth_private.h amok/amok_modinter.h \
        $(am__append_1) $(am__append_2) $(am__append_4) \
@@ -512,7 +512,7 @@ GTNETS_SRC = \
 
 # Separated because we don't want it in libsimgrid4java
 CTX_SRC = xbt/context.c
-JCTX_SRC = java/jxbt_context.c java/jxbt_context.h xbt/xbt_thread.c
+JCTX_SRC = java/jxbt_context.c java/jxbt_context.h xbt/xbt_os_thread.c
 SIMIX_SRC = \
   simix/smx_global.c \
   simix/smx_deployment.c \
@@ -567,7 +567,7 @@ GRAS_COMMON_SRC = \
   gras/DataDesc/ddt_parse.c           gras/DataDesc/ddt_parse.yy.c         gras/DataDesc/ddt_parse.yy.h
 
 GRAS_RL_SRC = \
-  gras/rl_stubs.c                     xbt/xbt_thread.c                    \
+  gras/rl_stubs.c                     xbt/xbt_os_thread.c                    \
   \
   gras/Transport/rl_transport.c          \
   gras/Transport/transport_plugin_file.c   gras/Transport/transport_plugin_tcp.c  \
@@ -584,7 +584,6 @@ GRAS_SG_SRC = gras/Transport/sg_transport.c  gras/Transport/transport_plugin_sg.
   gras/Virtu/sg_process.c        gras/Virtu/sg_time.c     \
   gras/Virtu/sg_dns.c\
   \
-  gras/sg_stubs.c                         \
   gras/Msg/sg_msg.c
 
 AMOK_SRC = \
@@ -822,7 +821,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_emul.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_msg.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_process.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_stubs.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_time.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_transport.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/simgrid_units_main.Po@am__quote@
@@ -855,10 +853,10 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_log_layout_simple.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_main.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_matrix.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_os_thread.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_peer.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_str.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_str_unit.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_thread.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xbt_virtu.Plo@am__quote@
 
 .c.o:
@@ -1176,12 +1174,12 @@ rl_stubs.lo: gras/rl_stubs.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o rl_stubs.lo `test -f 'gras/rl_stubs.c' || echo '$(srcdir)/'`gras/rl_stubs.c
 
-xbt_thread.lo: xbt/xbt_thread.c
-@am__fastdepCC_TRUE@   $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xbt_thread.lo -MD -MP -MF $(DEPDIR)/xbt_thread.Tpo -c -o xbt_thread.lo `test -f 'xbt/xbt_thread.c' || echo '$(srcdir)/'`xbt/xbt_thread.c
-@am__fastdepCC_TRUE@   mv -f $(DEPDIR)/xbt_thread.Tpo $(DEPDIR)/xbt_thread.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='xbt/xbt_thread.c' object='xbt_thread.lo' libtool=yes @AMDEPBACKSLASH@
+xbt_os_thread.lo: xbt/xbt_os_thread.c
+@am__fastdepCC_TRUE@   $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xbt_os_thread.lo -MD -MP -MF $(DEPDIR)/xbt_os_thread.Tpo -c -o xbt_os_thread.lo `test -f 'xbt/xbt_os_thread.c' || echo '$(srcdir)/'`xbt/xbt_os_thread.c
+@am__fastdepCC_TRUE@   mv -f $(DEPDIR)/xbt_os_thread.Tpo $(DEPDIR)/xbt_os_thread.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='xbt/xbt_os_thread.c' object='xbt_os_thread.lo' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xbt_thread.lo `test -f 'xbt/xbt_thread.c' || echo '$(srcdir)/'`xbt/xbt_thread.c
+@am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xbt_os_thread.lo `test -f 'xbt/xbt_os_thread.c' || echo '$(srcdir)/'`xbt/xbt_os_thread.c
 
 rl_transport.lo: gras/Transport/rl_transport.c
 @am__fastdepCC_TRUE@   $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT rl_transport.lo -MD -MP -MF $(DEPDIR)/rl_transport.Tpo -c -o rl_transport.lo `test -f 'gras/Transport/rl_transport.c' || echo '$(srcdir)/'`gras/Transport/rl_transport.c
@@ -1547,13 +1545,6 @@ sg_dns.lo: gras/Virtu/sg_dns.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sg_dns.lo `test -f 'gras/Virtu/sg_dns.c' || echo '$(srcdir)/'`gras/Virtu/sg_dns.c
 
-sg_stubs.lo: gras/sg_stubs.c
-@am__fastdepCC_TRUE@   $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sg_stubs.lo -MD -MP -MF $(DEPDIR)/sg_stubs.Tpo -c -o sg_stubs.lo `test -f 'gras/sg_stubs.c' || echo '$(srcdir)/'`gras/sg_stubs.c
-@am__fastdepCC_TRUE@   mv -f $(DEPDIR)/sg_stubs.Tpo $(DEPDIR)/sg_stubs.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='gras/sg_stubs.c' object='sg_stubs.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sg_stubs.lo `test -f 'gras/sg_stubs.c' || echo '$(srcdir)/'`gras/sg_stubs.c
-
 sg_msg.lo: gras/Msg/sg_msg.c
 @am__fastdepCC_TRUE@   $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sg_msg.lo -MD -MP -MF $(DEPDIR)/sg_msg.Tpo -c -o sg_msg.lo `test -f 'gras/Msg/sg_msg.c' || echo '$(srcdir)/'`gras/Msg/sg_msg.c
 @am__fastdepCC_TRUE@   mv -f $(DEPDIR)/sg_msg.Tpo $(DEPDIR)/sg_msg.Plo
index c041cdd..3ace03e 100644 (file)
@@ -74,6 +74,9 @@
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
+/* Define to 1 if you have the <jni.h> header file. */
+#undef HAVE_JNI_H
+
 /* Define to 1 if you have the `pthread' library (-lpthread). */
 #undef HAVE_LIBPTHREAD
 
diff --git a/src/include/xbt/xbt_os_thread.h b/src/include/xbt/xbt_os_thread.h
new file mode 100644 (file)
index 0000000..0796566
--- /dev/null
@@ -0,0 +1,62 @@
+/* $Id$ */
+
+/* xbt/xbt_thread.h -- Thread portability layer                             */
+
+/* Copyright (c) 2007 Martin Quinson. All rights reserved.                  */
+
+/* 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. */
+
+
+#ifndef _XBT_OS_THREAD_H
+#define _XBT_OS_THREAD_H
+
+#include "xbt/misc.h" /* SG_BEGIN_DECL */
+#include "xbt/function_types.h"
+
+SG_BEGIN_DECL()
+
+/** @addtogroup XBT_thread
+ *  @brief Thread portability layer
+ * 
+ *  This section describes the thread portability layer. It defines types and 
+ *  functions very close to the pthread API, but it's portable to windows too.
+ * 
+ *  @{
+ */
+
+  /** \brief Thread data type (opaque structure) */
+  typedef struct xbt_os_thread_       *xbt_os_thread_t;
+
+  XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_create(pvoid_f_pvoid_t start_routine,void* param);
+  XBT_PUBLIC(void) xbt_os_thread_exit(int *retcode);
+  XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_self(void);
+  /* xbt_os_thread_join frees the joined thread (ie the XBT wrapper around it, the OS frees the rest) */
+  XBT_PUBLIC(void) xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return);
+  XBT_PUBLIC(void) xbt_os_thread_yield(void);
+
+
+  /** \brief Thread mutex data type (opaque structure) */
+  typedef struct xbt_os_mutex_ *xbt_os_mutex_t;
+
+  XBT_PUBLIC(xbt_os_mutex_t) xbt_os_mutex_init(void);
+  XBT_PUBLIC(void)           xbt_os_mutex_lock(xbt_os_mutex_t mutex);
+  XBT_PUBLIC(void)           xbt_os_mutex_unlock(xbt_os_mutex_t mutex);
+  XBT_PUBLIC(void)           xbt_os_mutex_destroy(xbt_os_mutex_t mutex);
+
+
+  /** \brief Thread condition data type (opaque structure) */
+  typedef struct xbt_os_cond_  *xbt_os_cond_t;
+
+  XBT_PUBLIC(xbt_os_cond_t) xbt_os_cond_init(void);
+  XBT_PUBLIC(void)          xbt_os_cond_wait(xbt_os_cond_t cond,
+                                            xbt_os_mutex_t mutex);
+  XBT_PUBLIC(void)          xbt_os_cond_signal(xbt_os_cond_t cond);
+  XBT_PUBLIC(void)          xbt_os_cond_broadcast(xbt_os_cond_t cond);
+  XBT_PUBLIC(void)          xbt_os_cond_destroy(xbt_os_cond_t cond);
+
+/** @} */
+
+SG_END_DECL()
+
+#endif /* _XBT_OS_THREAD_H */
diff --git a/src/include/xbt/xbt_thread.h b/src/include/xbt/xbt_thread.h
deleted file mode 100644 (file)
index abe7632..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/* $Id$ */
-
-/* xbt/xbt_thread.h -- Thread portability layer                             */
-
-/* Copyright (c) 2007 Martin Quinson. All rights reserved.                  */
-
-/* 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. */
-
-
-#ifndef _XBT_THREAD_H
-#define _XBT_THREAD_H
-
-#include "xbt/misc.h" /* SG_BEGIN_DECL */
-#include "xbt/function_types.h"
-
-SG_BEGIN_DECL()
-
-/** @addtogroup XBT_thread
- *  @brief Thread portability layer
- * 
- *  This section describes the thread portability layer. It defines types and 
- *  functions very close to the pthread API, but it's portable to windows too.
- * 
- *  @{
- */
-
-  /** \brief Thread data type (opaque structure) */
-  typedef struct xbt_thread_       *xbt_thread_t;
-
-  XBT_PUBLIC(xbt_thread_t) xbt_thread_create(pvoid_f_pvoid_t start_routine,void* param);
-  XBT_PUBLIC(void) xbt_thread_exit(int *retcode);
-  XBT_PUBLIC(xbt_thread_t) xbt_thread_self(void);
-  /* xbt_thread_join frees the joined thread (ie the XBT wrapper around it, the OS frees the rest) */
-  XBT_PUBLIC(void) xbt_thread_join(xbt_thread_t thread,void ** thread_return);
-  XBT_PUBLIC(void) xbt_thread_yield(void);
-
-
-  /** \brief Thread mutex data type (opaque structure) */
-  typedef struct xbt_mutex_ *xbt_mutex_t;
-
-  XBT_PUBLIC(xbt_mutex_t) xbt_mutex_init(void);
-  XBT_PUBLIC(void)        xbt_mutex_lock(xbt_mutex_t mutex);
-  XBT_PUBLIC(void)        xbt_mutex_unlock(xbt_mutex_t mutex);
-  XBT_PUBLIC(void)        xbt_mutex_destroy(xbt_mutex_t mutex);
-
-
-  /** \brief Thread condition data type (opaque structure) */
-  typedef struct xbt_thcond_  *xbt_thcond_t;
-
-  XBT_PUBLIC(xbt_thcond_t) xbt_thcond_init(void);
-  XBT_PUBLIC(void)         xbt_thcond_wait(xbt_thcond_t cond,
-                                          xbt_mutex_t mutex);
-  XBT_PUBLIC(void)         xbt_thcond_signal(xbt_thcond_t cond);
-  XBT_PUBLIC(void)         xbt_thcond_broadcast(xbt_thcond_t cond);
-  XBT_PUBLIC(void)         xbt_thcond_destroy(xbt_thcond_t cond);
-
-/** @} */
-
-SG_END_DECL()
-
-#endif /* _XBT_DICT_H */
index d0438cc..0e539af 100644 (file)
@@ -1121,8 +1121,8 @@ Java_simgrid_msg_Msg_waitSignal(JNIEnv* env, jclass cls, jobject jprocess) {
   m_process_t m_process = jprocess_to_native_process(jprocess,env);
   smx_process_t s_process;
 
-  xbt_mutex_t ctx_mutex, creation_mutex;
-  xbt_thcond_t ctx_cond, creation_cond;
+  xbt_os_mutex_t ctx_mutex, creation_mutex;
+  xbt_os_cond_t ctx_cond, creation_cond;
 
   DEBUG3("Msg_waitSignal(m_process=%p %s/%s)",
         m_process,m_process->name,m_process->simdata->m_host->name);
@@ -1144,12 +1144,12 @@ Java_simgrid_msg_Msg_waitSignal(JNIEnv* env, jclass cls, jobject jprocess) {
   creation_mutex = xbt_creation_mutex_get();
   creation_cond = xbt_creation_cond_get();
 
-  xbt_mutex_lock(creation_mutex);
-  xbt_mutex_lock(ctx_mutex);
-  xbt_thcond_signal( creation_cond );
-  xbt_mutex_unlock( creation_mutex );
-  xbt_thcond_wait(ctx_cond, ctx_mutex);
-  xbt_mutex_unlock(ctx_mutex);
+  xbt_os_mutex_lock(creation_mutex);
+  xbt_os_mutex_lock(ctx_mutex);
+  xbt_os_cond_signal( creation_cond );
+  xbt_os_mutex_unlock( creation_mutex );
+  xbt_os_cond_wait(ctx_cond, ctx_mutex);
+  xbt_os_mutex_unlock(ctx_mutex);
 }
 
 JNIEXPORT void JNICALL 
index e9cd2a3..4934ce7 100644 (file)
@@ -11,7 +11,7 @@
 #include "portable.h"
 #include "xbt/log.h"
 #include "xbt/dynar.h"
-#include "xbt/xbt_thread.h"
+#include "xbt/xbt_os_thread.h"
 #include "java/jxbt_context.h"
 #include "java/jmsg.h"
 #include "java/jmsg_process.h"
@@ -27,10 +27,10 @@ static xbt_context_t current_context = NULL;    /* the current context                      */
 static xbt_context_t init_context = NULL;       /* the initial context                 */
 static xbt_swag_t context_to_destroy = NULL;    /* the list of the contexs to destroy  */
 static xbt_swag_t context_living = NULL;        /* the list of the contexts in use     */
-static xbt_mutex_t creation_mutex;              /* For syncronization during process creation */
-static xbt_thcond_t creation_cond;              /* For syncronization during process creation */
-static xbt_mutex_t master_mutex;               /* For syncronization during process scheduling*/
-static xbt_thcond_t master_cond;               /* For syncronization during process scheduling*/
+static xbt_os_mutex_t creation_mutex;              /* For syncronization during process creation */
+static xbt_os_cond_t creation_cond;              /* For syncronization during process creation */
+static xbt_os_mutex_t master_mutex;            /* For syncronization during process scheduling*/
+static xbt_os_cond_t master_cond;              /* For syncronization during process scheduling*/
 
 static void 
 __xbt_context_yield(xbt_context_t context);
@@ -50,15 +50,15 @@ __xbt_context_yield(xbt_context_t context) {
        * - restore thr current contex
        */
       
-      xbt_mutex_lock(master_mutex);
-      xbt_mutex_lock(context->mutex);
+      xbt_os_mutex_lock(master_mutex);
+      xbt_os_mutex_lock(context->mutex);
                        
       /* update the current context */
       current_context = context;
-      xbt_thcond_signal(context->cond);
-      xbt_mutex_unlock(context->mutex);
-      xbt_thcond_wait(master_cond, master_mutex);
-      xbt_mutex_unlock(master_mutex);
+      xbt_os_cond_signal(context->cond);
+      xbt_os_mutex_unlock(context->mutex);
+      xbt_os_cond_wait(master_cond, master_mutex);
+      xbt_os_mutex_unlock(master_mutex);
       /* retore the current context */
       current_context = self;
                        
@@ -70,14 +70,14 @@ __xbt_context_yield(xbt_context_t context) {
         * - restore thr current contex
         */
 
-       xbt_mutex_lock(master_mutex);
-       xbt_mutex_lock(context->mutex);
+       xbt_os_mutex_lock(master_mutex);
+       xbt_os_mutex_lock(context->mutex);
        /* update the current context */
        current_context = context;
-       xbt_thcond_signal(master_cond);
-       xbt_mutex_unlock(master_mutex);
-       xbt_thcond_wait(context->cond, context->mutex);
-       xbt_mutex_unlock(context->mutex);
+       xbt_os_cond_signal(master_cond);
+       xbt_os_mutex_unlock(master_mutex);
+       xbt_os_cond_wait(context->cond, context->mutex);
+       xbt_os_mutex_unlock(context->mutex);
        /* retore the current context */
        current_context = self;
       }
@@ -104,10 +104,10 @@ xbt_context_free(xbt_context_t context) {
     }
        
     /* destroy the mutex of the process */
-    xbt_mutex_destroy(context->mutex);
+    xbt_os_mutex_destroy(context->mutex);
 
     /* destroy the condition of the process */
-    xbt_thcond_destroy(context->cond);
+    xbt_os_cond_destroy(context->cond);
 
     context->mutex = NULL;
     context->cond = NULL;
@@ -137,10 +137,10 @@ __context_exit(xbt_context_t context ,int value) {
   /*
    * signal the condition of the java process 
    */
-  xbt_mutex_lock(master_mutex);
-  xbt_mutex_lock(context->mutex);
-  xbt_thcond_signal(context->cond);
-  xbt_mutex_unlock(context->mutex);
+  xbt_os_mutex_lock(master_mutex);
+  xbt_os_mutex_lock(context->mutex);
+  xbt_os_cond_signal(context->cond);
+  xbt_os_mutex_unlock(context->mutex);
        
   if (context->jprocess) {
     /* if the java process is alive, stop it */
@@ -172,10 +172,10 @@ jcontext_exit(xbt_context_t context ,int value,JNIEnv* env) {
   /*
    * signal the condition of the main thread.
    */
-  xbt_mutex_lock(master_mutex);
-  xbt_mutex_lock(context->mutex);
-  xbt_thcond_signal(master_cond);
-  xbt_mutex_unlock(master_mutex);
+  xbt_os_mutex_lock(master_mutex);
+  xbt_os_mutex_lock(context->mutex);
+  xbt_os_cond_signal(master_cond);
+  xbt_os_mutex_unlock(master_mutex);
        
        
   /* the global reference to the java process instance is deleted */
@@ -224,14 +224,14 @@ xbt_context_init(void) {
     xbt_swag_insert(init_context, context_living);
           
     /* this mutex is used to synchronize the creation of the java process */
-    creation_mutex = xbt_mutex_init();
+    creation_mutex = xbt_os_mutex_init();
     /* this mutex is used to synchronize the creation of the java process */
-    creation_cond = xbt_thcond_init();
+    creation_cond = xbt_os_cond_init();
 
     /* this mutex is used to synchronize the scheduling of the java process */
-    master_mutex = xbt_mutex_init();
+    master_mutex = xbt_os_mutex_init();
     /* this mutex is used to synchronize the scheduling of the java process */
-    master_cond = xbt_thcond_init();
+    master_cond = xbt_os_cond_init();
   }
 }
 
@@ -254,18 +254,18 @@ xbt_context_start(xbt_context_t context)  {
         context, context->jprocess, context->jenv);
 
   /* the main thread locks the mutex used to create all the process    */
-  xbt_mutex_lock(creation_mutex);
+  xbt_os_mutex_lock(creation_mutex);
 
   /* the main thread starts the java process                           */
   jprocess_start(context->jprocess,context->jenv);
 
   /* the main thread waits the startup of the java process             */
-  xbt_thcond_wait(creation_cond, creation_mutex);
+  xbt_os_cond_wait(creation_cond, creation_mutex);
        
   /* the java process is started, the main thread unlocks the mutex
    * used during the creation of the java process
    */
-  xbt_mutex_unlock(creation_mutex);
+  xbt_os_mutex_unlock(creation_mutex);
 }
 
 
@@ -278,8 +278,8 @@ xbt_context_new(xbt_context_function_t code,
 
   context->code = code;
        
-  context->mutex = xbt_mutex_init();
-  context->cond = xbt_thcond_init();
+  context->mutex = xbt_os_mutex_init();
+  context->cond = xbt_os_cond_init();
        
        
   context->argc = argc;
@@ -338,10 +338,10 @@ void xbt_context_exit(void)  {
   xbt_swag_free(context_to_destroy);
   xbt_swag_free(context_living);
        
-  xbt_mutex_destroy(creation_mutex);
-  xbt_thcond_destroy(creation_cond);
-  xbt_mutex_destroy(master_mutex);
-  xbt_thcond_destroy(master_cond);
+  xbt_os_mutex_destroy(creation_mutex);
+  xbt_os_cond_destroy(creation_cond);
+  xbt_os_mutex_destroy(master_mutex);
+  xbt_os_cond_destroy(master_cond);
 }
 
 /** 
@@ -354,12 +354,12 @@ void xbt_context_kill(xbt_context_t context) {
   __xbt_context_yield(context);
 }
 
-xbt_thcond_t
+xbt_os_cond_t
 xbt_creation_cond_get(void) {
   return creation_cond;
 }
 
-xbt_mutex_t
+xbt_os_mutex_t
 xbt_creation_mutex_get(void) {
   return creation_mutex;
 }
index 8fdd5a2..0797a9e 100644 (file)
@@ -18,7 +18,7 @@
 #include "portable.h"  /* loads context system definitions */
 #include "xbt/context.h"
 #include "xbt/ex.h"
-#include "xbt/xbt_thread.h"
+#include "xbt/xbt_os_thread.h"
 #include <jni.h>
 
 SG_BEGIN_DECL()
@@ -59,10 +59,10 @@ void __context_exit(xbt_context_t context ,int value);
 void jcontext_exit(xbt_context_t context ,int value,JNIEnv* env);
 
 /** Returns the condition used to synchronise the creation of a java process. */
-xbt_thcond_t xbt_creation_cond_get(void);
+xbt_os_cond_t xbt_creation_cond_get(void);
 
 /** Returns the mutex used to synchronise the creation of a java process */
-xbt_mutex_t xbt_creation_mutex_get(void);
+xbt_os_mutex_t xbt_creation_mutex_get(void);
 
 SG_END_DECL()
 
index 9ad4a8a..25cc9e6 100644 (file)
 #include "context_private.h"
 #include "xbt/log.h"
 #include "xbt/dynar.h"
-#include "xbt/xbt_thread.h"
-/*#include <pthread.h>*/ /* I need pthread_join that is not yet available in xbt_thread.*/
+#include "xbt/xbt_os_thread.h"
 
 #ifdef CONTEXT_THREADS
  /* This file (context.c) is only loaded in libsimgrid, not libgras.
-  * xbt_thread is only loaded in libgras explicitly, and we need it in 
+  * xbt_os_thread is only loaded in libgras explicitly, and we need it in 
   *    libsimgrid, but only when it is the backend used to implement the 
   *    xbt_context. So, do load it on need.
   */
-#include "xbt/xbt_thread.c"
+#include "xbt/xbt_os_thread.c"
+#else
+/* if not, load stubs so that all symbols get resolved anyway */
+#include "xbt/xbt_os_thread_stubs.c"
 #endif
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_ctx, xbt, "Context");
@@ -34,8 +36,8 @@ static xbt_context_t init_context = NULL;
 static xbt_swag_t context_to_destroy = NULL;
 static xbt_swag_t context_living = NULL;
 #ifdef CONTEXT_THREADS
-static xbt_mutex_t creation_mutex;
-static xbt_thcond_t creation_cond;
+static xbt_os_mutex_t creation_mutex;
+static xbt_os_cond_t creation_cond;
 #endif
 
 static void __context_exit(xbt_context_t context ,int value);
@@ -49,15 +51,15 @@ static void __xbt_context_yield(xbt_context_t context)
        if (context){
                xbt_context_t self = current_context;
                DEBUG2("[%p] **** Locking ctx %p ****", self, context);
-               xbt_mutex_lock(context->mutex);
+               xbt_os_mutex_lock(context->mutex);
                DEBUG1("[%p] **** Updating current_context ****", self);
                current_context = context;
                DEBUG1("[%p] **** Releasing the prisonner ****", self);
-               xbt_thcond_signal(context->cond);
+               xbt_os_cond_signal(context->cond);
                DEBUG3("[%p] **** Going to jail on individual %p/%p ****", self,context->cond, context->mutex);
-               xbt_thcond_wait(context->cond, context->mutex);
+               xbt_os_cond_wait(context->cond, context->mutex);
                DEBUG2("[%p] **** Unlocking individual %p ****", self,context->mutex);
-               xbt_mutex_unlock(context->mutex);
+               xbt_os_mutex_unlock(context->mutex);
                DEBUG1("[%p] **** Updating current_context ****", self);
                current_context = self;
        }
@@ -114,12 +116,12 @@ static void xbt_context_free(xbt_context_t context)
        /*DEBUG1("\t joining %p",(void *)context->thread->t);*/
        DEBUG1("\t joining %p",(void *)context->thread);
 
-       xbt_thread_join(context->thread,NULL);
+       xbt_os_thread_join(context->thread,NULL);
 
        DEBUG1("\t mutex_destroy %p",(void *)context->mutex);
-       xbt_mutex_destroy(context->mutex);
+       xbt_os_mutex_destroy(context->mutex);
        DEBUG1("\t cond_destroy %p",(void *)context->cond);
-       xbt_thcond_destroy(context->cond);
+       xbt_os_cond_destroy(context->cond);
 
        context->thread = NULL;
        context->mutex = NULL;
@@ -162,15 +164,15 @@ static void __context_exit(xbt_context_t context ,int value)
        
        #ifdef CONTEXT_THREADS
        DEBUG2("[%p] **** Locking %p ****", context, context->mutex);
-       xbt_mutex_lock(context->mutex);
+       xbt_os_mutex_lock(context->mutex);
 /*     DEBUG1("[%p] **** Updating current_context ****"); */
 /*     current_context = context; */
        DEBUG1("[%p] **** Releasing the prisonner ****", context);
-       xbt_thcond_signal(context->cond);
+       xbt_os_cond_signal(context->cond);
        DEBUG2("[%p] **** Unlocking individual %p ****", context, context->mutex);
-       xbt_mutex_unlock(context->mutex);
+       xbt_os_mutex_unlock(context->mutex);
        DEBUG1("[%p] **** Exiting ****", context);
-       xbt_thread_exit(NULL); // We should provide return value in case other wants it
+       xbt_os_thread_exit(NULL); // We should provide return value in case other wants it
        #else
        __xbt_context_yield(context);
        #endif
@@ -183,24 +185,24 @@ __context_wrapper(void* c) {
        
        #ifdef CONTEXT_THREADS
        context = (xbt_context_t)c;
-       context->thread = xbt_thread_self();
+       context->thread = xbt_os_thread_self();
         
-       DEBUG3("**[ctx:%p;self:%p]** Lock creation_mutex %p ****",context,(void*)xbt_thread_self(), creation_mutex);
-       xbt_mutex_lock(creation_mutex);
-       xbt_mutex_lock(context->mutex);
+       DEBUG3("**[ctx:%p;self:%p]** Lock creation_mutex %p ****",context,(void*)xbt_os_thread_self(), creation_mutex);
+       xbt_os_mutex_lock(creation_mutex);
+       xbt_os_mutex_lock(context->mutex);
        
        DEBUG4("**[ctx:%p;self:%p]** Releasing the creator (creation_cond %p,%p) ****",
-              context,(void*)xbt_thread_self(),creation_cond,creation_mutex);
-       xbt_thcond_signal(creation_cond);
-       xbt_mutex_unlock(creation_mutex);
+              context,(void*)xbt_os_thread_self(),creation_cond,creation_mutex);
+       xbt_os_cond_signal(creation_cond);
+       xbt_os_mutex_unlock(creation_mutex);
        
        DEBUG4("**[ctx:%p;self:%p]** Going to Jail on lock %p and cond %p ****",
-              context,(void*)xbt_thread_self(),context->mutex,context->cond);
-       xbt_thcond_wait(context->cond, context->mutex);
+              context,(void*)xbt_os_thread_self(),context->mutex,context->cond);
+       xbt_os_cond_wait(context->cond, context->mutex);
        
        DEBUG3("**[ctx:%p;self:%p]** Unlocking individual %p ****",
-              context,(void*)xbt_thread_self(),context->mutex);
-       xbt_mutex_unlock(context->mutex);
+              context,(void*)xbt_os_thread_self(),context->mutex);
+       xbt_os_mutex_unlock(context->mutex);
        
        #endif
        
@@ -254,8 +256,8 @@ void xbt_context_init(void)
                context_living = xbt_swag_new(xbt_swag_offset(*current_context,hookup));
                xbt_swag_insert(init_context, context_living);
 #ifdef CONTEXT_THREADS    
-               creation_mutex = xbt_mutex_init();
-               creation_cond = xbt_thcond_init();
+               creation_mutex = xbt_os_mutex_init();
+               creation_cond = xbt_os_cond_init();
 #endif    
        }
 }
@@ -284,18 +286,18 @@ void xbt_context_start(xbt_context_t context)
 {
        #ifdef CONTEXT_THREADS
        /* Launch the thread */
-       DEBUG3("**[ctx:%p;self:%p]** Locking creation_mutex %p ****",context,xbt_thread_self(),creation_mutex);
-       xbt_mutex_lock(creation_mutex);
+       DEBUG3("**[ctx:%p;self:%p]** Locking creation_mutex %p ****",context,xbt_os_thread_self(),creation_mutex);
+       xbt_os_mutex_lock(creation_mutex);
    
-       DEBUG2("**[ctx:%p;self:%p]** Thread create ****",context,xbt_thread_self());
-        context->thread = xbt_thread_create(__context_wrapper, context);   
-       DEBUG3("**[ctx:%p;self:%p]** Thread created : %p ****",context,xbt_thread_self(),context->thread);
+       DEBUG2("**[ctx:%p;self:%p]** Thread create ****",context,xbt_os_thread_self());
+        context->thread = xbt_os_thread_create(__context_wrapper, context);   
+       DEBUG3("**[ctx:%p;self:%p]** Thread created : %p ****",context,xbt_os_thread_self(),context->thread);
    
        DEBUG4("**[ctx:%p;self:%p]** Going to jail on creation_cond/mutex (%p,%p) ****",
-              context,xbt_thread_self(),creation_cond, creation_mutex);
-       xbt_thcond_wait(creation_cond, creation_mutex);
-       DEBUG3("**[ctx:%p;self:%p]** Unlocking creation %p ****",context, xbt_thread_self(),creation_mutex);
-       xbt_mutex_unlock(creation_mutex);
+              context,xbt_os_thread_self(),creation_cond, creation_mutex);
+       xbt_os_cond_wait(creation_cond, creation_mutex);
+       DEBUG3("**[ctx:%p;self:%p]** Unlocking creation %p ****",context, xbt_os_thread_self(),creation_mutex);
+       xbt_os_mutex_unlock(creation_mutex);
        #else
        makecontext (&(context->uc), (void (*) (void)) __context_wrapper,1, context);
        #endif
@@ -324,8 +326,8 @@ xbt_context_t xbt_context_new(xbt_context_function_t code,
        
        res->code = code;
        #ifdef CONTEXT_THREADS
-       res->mutex = xbt_mutex_init();
-        res->cond = xbt_thcond_init();
+       res->mutex = xbt_os_mutex_init();
+        res->cond = xbt_os_cond_init();
        #else 
 
        xbt_assert2(getcontext(&(res->uc))==0,"Error in context saving: %d (%s)", errno, strerror(errno));
@@ -398,8 +400,8 @@ void xbt_context_exit(void) {
        xbt_swag_free(context_living);
        
 #ifdef CONTEXT_THREADS    
-       xbt_mutex_destroy(creation_mutex);
-       xbt_thcond_destroy(creation_cond);
+       xbt_os_mutex_destroy(creation_mutex);
+       xbt_os_cond_destroy(creation_cond);
 #endif   
 }
 
index 7778861..2cf2a2e 100644 (file)
@@ -22,7 +22,7 @@
 #include "xbt/ex.h"
 
 #ifdef CONTEXT_THREADS
-#  include "xbt/xbt_thread.h"
+#  include "xbt/xbt_os_thread.h"
 #else
 #  include <ucontext.h>
 #  define STACK_SIZE 128*1024 /* Lower this if you want to reduce the memory consumption */
@@ -38,7 +38,7 @@ typedef struct s_xbt_context {
        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) */
+       xbt_os_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];
@@ -48,8 +48,8 @@ typedef struct s_xbt_context {
    
        /* 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            */
+       xbt_os_cond_t cond;             /* the condition used to synchronize the process        */
+       xbt_os_mutex_t mutex;           /* the mutex used to synchronize the process            */
 #endif
 
        /* What to run */
index f16ad00..e1410b3 100644 (file)
@@ -36,7 +36,7 @@ xbt_init(int *argc, char **argv) {
   VERB0("Initialize XBT");
   
   xbt_log_init(argc,argv);
-  xbt_thread_mod_init();
+  xbt_os_thread_mod_init();
   xbt_context_init();
 }
 
@@ -48,7 +48,7 @@ xbt_exit(){
     xbt_fifo_exit();
     xbt_dict_exit();
     xbt_context_exit();
-    xbt_thread_mod_exit();
+    xbt_os_thread_mod_exit();
     xbt_log_exit();
   }
    
similarity index 77%
rename from src/xbt/xbt_thread.c
rename to src/xbt/xbt_os_thread.c
index 0aef1c1..91b38fe 100644 (file)
@@ -1,6 +1,8 @@
 /* $Id$ */
 
-/* xbt_thread -- portability layer over the pthread API                     */
+/* xbt_os_thread -- portability layer over the pthread API                  */
+/* Used in RL to get win/lin portability, and in SG when CONTEXT_THREAD     */
+/* in SG, when using CONTEXT_UCONTEXT, xbt_os_thread_stub is used instead   */
 
 /* Copyright 2006,2007 Malek Cherier, Martin Quinson          
  * All right reserved.                                                      */
@@ -11,7 +13,7 @@
 #include "xbt/sysdep.h"
 #include "xbt/ex.h"
 #include "portable.h"
-#include "xbt/xbt_thread.h" /* This module */
+#include "xbt/xbt_os_thread.h" /* This module */
 #include "xbt_modinter.h" /* Initialization/finalization of this module */
 
 
 #ifdef HAVE_PTHREAD_H
 #include <pthread.h>
 
-typedef struct xbt_thread_ {
+typedef struct xbt_os_thread_ {
    pthread_t t;
    void *param;
    pvoid_f_pvoid_t *start_routine;
-} s_xbt_thread_t ;
+} s_xbt_os_thread_t ;
 
-/* thread-specific data containing the xbt_thread_t structure */
+/* thread-specific data containing the xbt_os_thread_t structure */
 static pthread_key_t xbt_self_thread_key;
 
-/* frees the xbt_thread_t corresponding to the current thread */
-static void xbt_thread_free_thread_data(void*d){
+/* frees the xbt_os_thread_t corresponding to the current thread */
+static void xbt_os_thread_free_thread_data(void*d){
    free(d);
 }
 
-void xbt_thread_mod_init(void) {
+void xbt_os_thread_mod_init(void) {
    int errcode;
    
    if ((errcode=pthread_key_create(&xbt_self_thread_key, NULL)))
      THROW0(system_error,errcode,"pthread_key_create failed for xbt_self_thread_key");
 }
-void xbt_thread_mod_exit(void) {
+void xbt_os_thread_mod_exit(void) {
    /* FIXME: don't try to free our key on shutdown. Valgrind detects no leak if we don't, and whine if we try to */
 //   int errcode;
    
@@ -49,7 +51,7 @@ void xbt_thread_mod_exit(void) {
 }
 
 static void * wrapper_start_routine(void *s) {
-  xbt_thread_t t = s;   
+  xbt_os_thread_t t = s;   
   int errcode;
 
   if ((errcode=pthread_setspecific(xbt_self_thread_key,t)))
@@ -57,11 +59,11 @@ static void * wrapper_start_routine(void *s) {
   return t->start_routine(t->param);
 }
 
-xbt_thread_t xbt_thread_create(pvoid_f_pvoid_t start_routine,
-                              void* param)  {
+xbt_os_thread_t xbt_os_thread_create(pvoid_f_pvoid_t start_routine,
+                                    void* param)  {
    int errcode;
 
-   xbt_thread_t res_thread=xbt_new(s_xbt_thread_t,1);
+   xbt_os_thread_t res_thread=xbt_new(s_xbt_os_thread_t,1);
    res_thread->start_routine = start_routine;
    res_thread->param = param;
 
@@ -73,7 +75,7 @@ xbt_thread_t xbt_thread_create(pvoid_f_pvoid_t start_routine,
 }
 
 void 
-xbt_thread_join(xbt_thread_t thread,void ** thread_return) {
+xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return) {
        
        int errcode;   
        
@@ -83,25 +85,25 @@ xbt_thread_join(xbt_thread_t thread,void ** thread_return) {
        free(thread);   
 }                     
 
-void xbt_thread_exit(int *retval) {
+void xbt_os_thread_exit(int *retval) {
    pthread_exit(retval);
 }
 
-xbt_thread_t xbt_thread_self(void) {
+xbt_os_thread_t xbt_os_thread_self(void) {
    return pthread_getspecific(xbt_self_thread_key);
 }
 
 #include <sched.h>
-void xbt_thread_yield(void) {
+void xbt_os_thread_yield(void) {
    sched_yield();
 }
 /****** mutex related functions ******/
-typedef struct xbt_mutex_ {
+typedef struct xbt_os_mutex_ {
    pthread_mutex_t m;
-} s_xbt_mutex_t;
+} s_xbt_os_mutex_t;
 
-xbt_mutex_t xbt_mutex_init(void) {
-   xbt_mutex_t res = xbt_new(s_xbt_mutex_t,1);
+xbt_os_mutex_t xbt_os_mutex_init(void) {
+   xbt_os_mutex_t res = xbt_new(s_xbt_os_mutex_t,1);
    int errcode;
    
    if ((errcode = pthread_mutex_init(&(res->m),NULL)))
@@ -111,7 +113,7 @@ xbt_mutex_t xbt_mutex_init(void) {
    return res;
 }
 
-void xbt_mutex_lock(xbt_mutex_t mutex) {
+void xbt_os_mutex_lock(xbt_os_mutex_t mutex) {
    int errcode;
    
    if ((errcode=pthread_mutex_lock(&(mutex->m))))
@@ -119,7 +121,7 @@ void xbt_mutex_lock(xbt_mutex_t mutex) {
            mutex, strerror(errcode));
 }
 
-void xbt_mutex_unlock(xbt_mutex_t mutex) {
+void xbt_os_mutex_unlock(xbt_os_mutex_t mutex) {
    int errcode;
    
    if ((errcode=pthread_mutex_unlock(&(mutex->m))))
@@ -127,7 +129,7 @@ void xbt_mutex_unlock(xbt_mutex_t mutex) {
            mutex, strerror(errcode));
 }
 
-void xbt_mutex_destroy(xbt_mutex_t mutex) {
+void xbt_os_mutex_destroy(xbt_os_mutex_t mutex) {
    int errcode;
    
    if (!mutex) return;
@@ -139,12 +141,12 @@ void xbt_mutex_destroy(xbt_mutex_t mutex) {
 }
 
 /***** condition related functions *****/
-typedef struct xbt_thcond_ {
+typedef struct xbt_os_cond_ {
    pthread_cond_t c;
-} s_xbt_thcond_t;
+} s_xbt_os_cond_t;
 
-xbt_thcond_t xbt_thcond_init(void) {
-   xbt_thcond_t res = xbt_new(s_xbt_thcond_t,1);
+xbt_os_cond_t xbt_os_cond_init(void) {
+   xbt_os_cond_t res = xbt_new(s_xbt_os_cond_t,1);
    int errcode;
    if ((errcode=pthread_cond_init(&(res->c),NULL)))
      THROW1(system_error,errcode,"pthread_cond_init() failed: %s",
@@ -153,27 +155,27 @@ xbt_thcond_t xbt_thcond_init(void) {
    return res;
 }
 
-void xbt_thcond_wait(xbt_thcond_t cond, xbt_mutex_t mutex) {
+void xbt_os_cond_wait(xbt_os_cond_t cond, xbt_os_mutex_t mutex) {
    int errcode;
    if ((errcode=pthread_cond_wait(&(cond->c),&(mutex->m))))
      THROW3(system_error,errcode,"pthread_cond_wait(%p,%p) failed: %s",
            cond,mutex, strerror(errcode));
 }
 
-void xbt_thcond_signal(xbt_thcond_t cond) {
+void xbt_os_cond_signal(xbt_os_cond_t cond) {
    int errcode;
    if ((errcode=pthread_cond_signal(&(cond->c))))
      THROW2(system_error,errcode,"pthread_cond_signal(%p) failed: %s",
            cond, strerror(errcode));
 }
         
-void xbt_thcond_broadcast(xbt_thcond_t cond){
+void xbt_os_cond_broadcast(xbt_os_cond_t cond){
    int errcode;
    if ((errcode=pthread_cond_broadcast(&(cond->c))))
      THROW2(system_error,errcode,"pthread_cond_broadcast(%p) failed: %s",
            cond, strerror(errcode));
 }
-void xbt_thcond_destroy(xbt_thcond_t cond){
+void xbt_os_cond_destroy(xbt_os_cond_t cond){
    int errcode;
 
    if (!cond) return;
@@ -188,27 +190,27 @@ void xbt_thcond_destroy(xbt_thcond_t cond){
 
 #elif defined(WIN32)
 
-typedef struct xbt_thread_ {
+typedef struct xbt_os_thread_ {
   HANDLE handle;                  /* the win thread handle        */
   unsigned long id;               /* the win thread id            */
   pvoid_f_pvoid_t *start_routine;
   void* param;
-} s_xbt_thread_t ;
+} s_xbt_os_thread_t ;
 
-/* key to the TLS containing the xbt_thread_t structure */
+/* key to the TLS containing the xbt_os_thread_t structure */
 static unsigned long xbt_self_thread_key;
 
-void xbt_thread_mod_init(void) {
+void xbt_os_thread_mod_init(void) {
    xbt_self_thread_key = TlsAlloc();
 }
-void xbt_thread_mod_exit(void) {
+void xbt_os_thread_mod_exit(void) {
    
    if (!TlsFree(xbt_self_thread_key)) 
      THROW0(system_error,(int)GetLastError(),"TlsFree() failed to cleanup the thread submodule");
 }
 
 static DWORD WINAPI  wrapper_start_routine(void *s) {
-  xbt_thread_t t = (xbt_thread_t)s;
+  xbt_os_thread_t t = (xbt_os_thread_t)s;
  
     if(!TlsSetValue(xbt_self_thread_key,t))
      THROW0(system_error,(int)GetLastError(),"TlsSetValue of data describing the created thread failed");
@@ -217,10 +219,10 @@ static DWORD WINAPI  wrapper_start_routine(void *s) {
 }
 
 
-xbt_thread_t xbt_thread_create(pvoid_f_pvoid_t start_routine,
+xbt_os_thread_t xbt_os_thread_create(pvoid_f_pvoid_t start_routine,
                               void* param)  {
    
-   xbt_thread_t t = xbt_new(s_xbt_thread_t,1);
+   xbt_os_thread_t t = xbt_new(s_xbt_os_thread_t,1);
 
    t->start_routine = start_routine ;
    t->param = param;
@@ -238,7 +240,7 @@ xbt_thread_t xbt_thread_create(pvoid_f_pvoid_t start_routine,
 }
 
 void 
-xbt_thread_join(xbt_thread_t thread,void ** thread_return) {
+xbt_os_thread_join(xbt_os_thread_t thread,void ** thread_return) {
 
        if(WAIT_OBJECT_0 != WaitForSingleObject(thread->handle,INFINITE))  
                THROW0(system_error,(int)GetLastError(), "WaitForSingleObject failed");
@@ -253,28 +255,28 @@ xbt_thread_join(xbt_thread_t thread,void ** thread_return) {
        free(thread);
 }
 
-void xbt_thread_exit(int *retval) {
+void xbt_os_thread_exit(int *retval) {
    if(retval)
        ExitThread(*retval);
    else
        ExitThread(0);
 }
 
-xbt_thread_t xbt_thread_self(void) {
+xbt_os_thread_t xbt_os_thread_self(void) {
    return TlsGetValue(xbt_self_thread_key);
 }
 
-void xbt_thread_yield(void) {
+void xbt_os_thread_yield(void) {
     Sleep(0);
 }
 
 /****** mutex related functions ******/
-typedef struct xbt_mutex_ {
+typedef struct xbt_os_mutex_ {
    CRITICAL_SECTION lock;   
-} s_xbt_mutex_t;
+} s_xbt_os_mutex_t;
 
-xbt_mutex_t xbt_mutex_init(void) {
-   xbt_mutex_t res = xbt_new(s_xbt_mutex_t,1);
+xbt_os_mutex_t xbt_os_mutex_init(void) {
+   xbt_os_mutex_t res = xbt_new(s_xbt_os_mutex_t,1);
 
    /* initialize the critical section object */
    InitializeCriticalSection(&(res->lock));
@@ -282,18 +284,18 @@ xbt_mutex_t xbt_mutex_init(void) {
    return res;
 }
 
-void xbt_mutex_lock(xbt_mutex_t mutex) {
+void xbt_os_mutex_lock(xbt_os_mutex_t mutex) {
 
    EnterCriticalSection(& mutex->lock);
 }
 
-void xbt_mutex_unlock(xbt_mutex_t mutex) {
+void xbt_os_mutex_unlock(xbt_os_mutex_t mutex) {
 
    LeaveCriticalSection (& mutex->lock);
 
 }
 
-void xbt_mutex_destroy(xbt_mutex_t mutex) {
+void xbt_os_mutex_destroy(xbt_os_mutex_t mutex) {
 
    if (!mutex) return;
    
@@ -308,16 +310,16 @@ void xbt_mutex_destroy(xbt_mutex_t mutex) {
     MAX_EVENTS = 2
  };
 
-typedef struct xbt_thcond_ {
+typedef struct xbt_os_cond_ {
    HANDLE events[MAX_EVENTS];
    
    unsigned int waiters_count;           /* the number of waiters                        */
    CRITICAL_SECTION waiters_count_lock;  /* protect access to waiters_count  */
-} s_xbt_thcond_t;
+} s_xbt_os_cond_t;
 
-xbt_thcond_t xbt_thcond_init(void) {
+xbt_os_cond_t xbt_os_cond_init(void) {
 
-   xbt_thcond_t res = xbt_new0(s_xbt_thcond_t,1);
+   xbt_os_cond_t res = xbt_new0(s_xbt_os_cond_t,1);
        
    memset(& res->waiters_count_lock,0,sizeof(CRITICAL_SECTION));
        
@@ -349,7 +351,7 @@ xbt_thcond_t xbt_thcond_init(void) {
    return res;
 }
 
-void xbt_thcond_wait(xbt_thcond_t cond, xbt_mutex_t mutex) {
+void xbt_os_cond_wait(xbt_os_cond_t cond, xbt_os_mutex_t mutex) {
        
    unsigned long wait_result;
    int is_last_waiter;
@@ -389,7 +391,7 @@ void xbt_thcond_wait(xbt_thcond_t cond, xbt_mutex_t mutex) {
    EnterCriticalSection (& mutex->lock);
 }
 
-void xbt_thcond_signal(xbt_thcond_t cond) {
+void xbt_os_cond_signal(xbt_os_cond_t cond) {
    int have_waiters;
 
    EnterCriticalSection (& cond->waiters_count_lock);
@@ -400,10 +402,10 @@ void xbt_thcond_signal(xbt_thcond_t cond) {
      if(!SetEvent(cond->events[SIGNAL]))
        THROW0(system_error,0,"SetEvent failed");
        
-   xbt_thread_yield();
+   xbt_os_thread_yield();
 }
 
-void xbt_thcond_broadcast(xbt_thcond_t cond){
+void xbt_os_cond_broadcast(xbt_os_cond_t cond){
    int have_waiters;
 
    EnterCriticalSection (& cond->waiters_count_lock);
@@ -414,7 +416,7 @@ void xbt_thcond_broadcast(xbt_thcond_t cond){
      SetEvent(cond->events[BROADCAST]);
 }
 
-void xbt_thcond_destroy(xbt_thcond_t cond){
+void xbt_os_cond_destroy(xbt_os_cond_t cond){
    int error = 0;
    
    if (!cond) return;
index 508e138..1064e47 100644 (file)
@@ -20,7 +20,7 @@ void xbt_dict_exit(void);
 void xbt_context_init(void);
 void xbt_context_exit(void);
 
-void xbt_thread_mod_init(void);
-void xbt_thread_mod_exit(void);   
+void xbt_os_thread_mod_init(void);
+void xbt_os_thread_mod_exit(void);   
    
 #endif /* XBT_MODINTER_H */