Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Hello module xbt/queue (classical producer/consumer synchronization scheme)
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 9 Jul 2007 18:41:52 +0000 (18:41 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 9 Jul 2007 18:41:52 +0000 (18:41 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3703 48e7efb5-ca39-0410-a469-dd3cf9ba447f

ChangeLog
examples/gras/all2all/Makefile.in
include/Makefile.am
include/Makefile.in
include/xbt/queue.h [new file with mode: 0644]
src/Makefile.am
src/Makefile.in
src/xbt/queue.c [new file with mode: 0644]

index a34270e..6281375 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,13 +26,15 @@ SimGrid (3.3-cvs) unstable; urgency=low
 
  XBT:
   * Make the backtrace of exceptions more human readable [Mt]
+  * New module: xbt/str [Mt]
+    a ton of string utility functions (split, join, printf to a newly
+    allocated buffer, trim, etc)
   * New module: xbt/synchro [Mt]
     synchronization tools (mutex and conditions) working the same way
     in simulation and in real life (mainly useful for GRAS, but not
     only).
-  * New module: xbt/str [Mt]
-    a ton of string utility functions (split, join, printf to a newly
-    allocated buffer, trim, etc)    
+  * New module: xbt/queue [Mt]
+    classical producer/consumer synchronization scheme
 
  -- 
 
index c772f57..c205f03 100644 (file)
@@ -1,8 +1,8 @@
-# Makefile.in generated by automake 1.9.6 from Makefile.am.
+# Makefile.in generated by automake 1.10 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005  Free Software Foundation, Inc.
+# 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
 # It is intended to be included in all Makefile.am 
 
-srcdir = @srcdir@
-top_srcdir = @top_srcdir@
 VPATH = @srcdir@
 pkgdatadir = $(datadir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
-top_builddir = ../../..
 am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
-INSTALL = @INSTALL@
 install_sh_DATA = $(install_sh) -c -m 644
 install_sh_PROGRAM = $(install_sh) -c
 install_sh_SCRIPT = $(install_sh) -c
@@ -89,17 +85,18 @@ am_all2all_simulator_OBJECTS = _all2all_simulator.$(OBJEXT) \
        all2all.$(OBJEXT)
 all2all_simulator_OBJECTS = $(am_all2all_simulator_OBJECTS)
 all2all_simulator_DEPENDENCIES = $(top_builddir)/src/libsimgrid.la
-DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/src
+DEFAULT_INCLUDES = -I. -I$(top_builddir)/src@am__isrc@
 depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
-       $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
-       $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+       --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+       $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
-LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-       $(AM_LDFLAGS) $(LDFLAGS) -o $@
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+       --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+       $(LDFLAGS) -o $@
 SOURCES = $(all2all_receiver_SOURCES) $(all2all_sender_SOURCES) \
        $(all2all_simulator_SOURCES)
 DIST_SOURCES = $(all2all_receiver_SOURCES) $(all2all_sender_SOURCES) \
@@ -109,8 +106,6 @@ CTAGS = ctags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 ADDR2LINE = @ADDR2LINE@
-AMDEP_FALSE = @AMDEP_FALSE@
-AMDEP_TRUE = @AMDEP_TRUE@
 AMTAR = @AMTAR@
 AM_CFLAGS = @AM_CFLAGS@
 AR = @AR@
@@ -141,22 +136,21 @@ ECHO_T = @ECHO_T@
 EGREP = @EGREP@
 EXEEXT = @EXEEXT@
 FLEXML = @FLEXML@
-GRAMINE_MODE_FALSE = @GRAMINE_MODE_FALSE@
-GRAMINE_MODE_TRUE = @GRAMINE_MODE_TRUE@
-GRAS_ARCH_32_BITS_FALSE = @GRAS_ARCH_32_BITS_FALSE@
-GRAS_ARCH_32_BITS_TRUE = @GRAS_ARCH_32_BITS_TRUE@
+GCJ = @GCJ@
+GCJDEPMODE = @GCJDEPMODE@
+GCJFLAGS = @GCJFLAGS@
 GRAS_DEP = @GRAS_DEP@
 GREP = @GREP@
 GTNETS_CFLAGS = @GTNETS_CFLAGS@
 GTNETS_LDFLAGS = @GTNETS_LDFLAGS@
-HAVE_FLEXML_FALSE = @HAVE_FLEXML_FALSE@
-HAVE_FLEXML_TRUE = @HAVE_FLEXML_TRUE@
-HAVE_SDP_FALSE = @HAVE_SDP_FALSE@
-HAVE_SDP_TRUE = @HAVE_SDP_TRUE@
+INSTALL = @INSTALL@
 INSTALL_DATA = @INSTALL_DATA@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+JAR = @JAR@
+JAVA = @JAVA@
+JAVAC = @JAVAC@
 LDFLAGS = @LDFLAGS@
 LD_DYNAMIC_FLAGS = @LD_DYNAMIC_FLAGS@
 LEX = @LEX@
@@ -168,10 +162,9 @@ LIBTOOL = @LIBTOOL@
 LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
-MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
-MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
 MAKEINFO = @MAKEINFO@
 MD5SUM = @MD5SUM@
+MKDIR_P = @MKDIR_P@
 OBJDUMP = @OBJDUMP@
 OBJEXT = @OBJEXT@
 PACKAGE = @PACKAGE@
@@ -187,8 +180,6 @@ SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
 SIMGRID_DEP = @SIMGRID_DEP@
 STRIP = @STRIP@
-USE_GTNETS_FALSE = @USE_GTNETS_FALSE@
-USE_GTNETS_TRUE = @USE_GTNETS_TRUE@
 VERSION = @VERSION@
 WARNING = @WARNING@
 abs_builddir = @abs_builddir@
@@ -198,10 +189,6 @@ abs_top_srcdir = @abs_top_srcdir@
 ac_configure_args = @ac_configure_args@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_CXX = @ac_ct_CXX@
-am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
-am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
-am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
-am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
 am__include = @am__include@
 am__leading_dot = @am__leading_dot@
 am__quote = @am__quote@
@@ -214,6 +201,7 @@ build_cpu = @build_cpu@
 build_id = @build_id@
 build_os = @build_os@
 build_vendor = @build_vendor@
+builddir = @builddir@
 datadir = @datadir@
 datarootdir = @datarootdir@
 docdir = @docdir@
@@ -243,12 +231,15 @@ pth_skaddr_makecontext = @pth_skaddr_makecontext@
 pth_sksize_makecontext = @pth_sksize_makecontext@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
 sysconfdir = @sysconfdir@
 target = @target@
 target_alias = @target_alias@
 target_cpu = @target_cpu@
 target_os = @target_os@
 target_vendor = @target_vendor@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
 INCLUDES = -I$(top_srcdir)/include
 EXTRA_DIST = all2all.xml test_rl test_sg_32 test_sg_64
 @GRAS_ARCH_32_BITS_FALSE@TESTS = test_sg_64 test_rl
@@ -310,13 +301,13 @@ clean-noinstPROGRAMS:
        done
 all2all_receiver$(EXEEXT): $(all2all_receiver_OBJECTS) $(all2all_receiver_DEPENDENCIES) 
        @rm -f all2all_receiver$(EXEEXT)
-       $(LINK) $(all2all_receiver_LDFLAGS) $(all2all_receiver_OBJECTS) $(all2all_receiver_LDADD) $(LIBS)
+       $(LINK) $(all2all_receiver_OBJECTS) $(all2all_receiver_LDADD) $(LIBS)
 all2all_sender$(EXEEXT): $(all2all_sender_OBJECTS) $(all2all_sender_DEPENDENCIES) 
        @rm -f all2all_sender$(EXEEXT)
-       $(LINK) $(all2all_sender_LDFLAGS) $(all2all_sender_OBJECTS) $(all2all_sender_LDADD) $(LIBS)
+       $(LINK) $(all2all_sender_OBJECTS) $(all2all_sender_LDADD) $(LIBS)
 all2all_simulator$(EXEEXT): $(all2all_simulator_OBJECTS) $(all2all_simulator_DEPENDENCIES) 
        @rm -f all2all_simulator$(EXEEXT)
-       $(LINK) $(all2all_simulator_LDFLAGS) $(all2all_simulator_OBJECTS) $(all2all_simulator_LDADD) $(LIBS)
+       $(LINK) $(all2all_simulator_OBJECTS) $(all2all_simulator_LDADD) $(LIBS)
 
 mostlyclean-compile:
        -rm -f *.$(OBJEXT)
@@ -330,22 +321,22 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/all2all.Po@am__quote@
 
 .c.o:
-@am__fastdepCC_TRUE@   if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
-@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@am__fastdepCC_TRUE@   $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(COMPILE) -c $<
 
 .c.obj:
-@am__fastdepCC_TRUE@   if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
-@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@am__fastdepCC_TRUE@   $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@   mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(COMPILE) -c `$(CYGPATH_W) '$<'`
 
 .c.lo:
-@am__fastdepCC_TRUE@   if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
-@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@am__fastdepCC_TRUE@   $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LTCOMPILE) -c -o $@ $<
@@ -356,10 +347,6 @@ mostlyclean-libtool:
 clean-libtool:
        -rm -rf .libs _libs
 
-distclean-libtool:
-       -rm -f libtool
-uninstall-info-am:
-
 ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
        list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
        unique=`for i in $$list; do \
@@ -409,9 +396,9 @@ distclean-tags:
        -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 
 check-TESTS: $(TESTS)
-       @failed=0; all=0; xfail=0; xpass=0; skip=0; \
+       @failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[        ]'; \
        srcdir=$(srcdir); export srcdir; \
-       list='$(TESTS)'; \
+       list=' $(TESTS) '; \
        if test -n "$$list"; then \
          for tst in $$list; do \
            if test -f ./$$tst; then dir=./; \
@@ -420,7 +407,7 @@ check-TESTS: $(TESTS)
            if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
              all=`expr $$all + 1`; \
              case " $(XFAIL_TESTS) " in \
-             *" $$tst "*) \
+             *$$ws$$tst$$ws*) \
                xpass=`expr $$xpass + 1`; \
                failed=`expr $$failed + 1`; \
                echo "XPASS: $$tst"; \
@@ -432,7 +419,7 @@ check-TESTS: $(TESTS)
            elif test $$? -ne 77; then \
              all=`expr $$all + 1`; \
              case " $(XFAIL_TESTS) " in \
-             *" $$tst "*) \
+             *$$ws$$tst$$ws*) \
                xfail=`expr $$xfail + 1`; \
                echo "XFAIL: $$tst"; \
              ;; \
@@ -482,23 +469,21 @@ check-TESTS: $(TESTS)
        else :; fi
 
 distdir: $(DISTFILES)
-       $(mkdir_p) $(distdir)/../../../acmacro $(distdir)/../../../examples $(distdir)/../../../examples/gras
-       @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
-       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
-       list='$(DISTFILES)'; for file in $$list; do \
-         case $$file in \
-           $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
-           $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
-         esac; \
+       @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       list='$(DISTFILES)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
          if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
-         dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
-         if test "$$dir" != "$$file" && test "$$dir" != "."; then \
-           dir="/$$dir"; \
-           $(mkdir_p) "$(distdir)$$dir"; \
-         else \
-           dir=''; \
-         fi; \
          if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
            if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
              cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
            fi; \
@@ -549,7 +534,7 @@ distclean: distclean-am
        -rm -rf ./$(DEPDIR)
        -rm -f Makefile
 distclean-am: clean-am distclean-compile distclean-generic \
-       distclean-libtool distclean-tags
+       distclean-tags
 
 dvi: dvi-am
 
@@ -563,12 +548,20 @@ info-am:
 
 install-data-am:
 
+install-dvi: install-dvi-am
+
 install-exec-am:
 
+install-html: install-html-am
+
 install-info: install-info-am
 
 install-man:
 
+install-pdf: install-pdf-am
+
+install-ps: install-ps-am
+
 installcheck-am:
 
 maintainer-clean: maintainer-clean-am
@@ -589,19 +582,23 @@ ps: ps-am
 
 ps-am:
 
-uninstall-am: uninstall-info-am
+uninstall-am:
+
+.MAKE: install-am install-strip
 
 .PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \
        clean-generic clean-libtool clean-noinstPROGRAMS ctags \
        distclean distclean-compile distclean-generic \
        distclean-libtool distclean-tags distdir dvi dvi-am html \
        html-am info info-am install install-am install-data \
-       install-data-am install-exec install-exec-am install-info \
-       install-info-am install-man install-strip installcheck \
+       install-data-am install-dvi install-dvi-am install-exec \
+       install-exec-am install-html install-html-am install-info \
+       install-info-am install-man install-pdf install-pdf-am \
+       install-ps install-ps-am install-strip installcheck \
        installcheck-am installdirs maintainer-clean \
        maintainer-clean-generic mostlyclean mostlyclean-compile \
        mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
-       tags uninstall uninstall-am uninstall-info-am
+       tags uninstall uninstall-am
 
 @GRAS_ARCH_32_BITS_TRUE@test-sg: 
 @GRAS_ARCH_32_BITS_TRUE@       $(TESTS_ENVIRONMENT) test_sg_32
index bce9800..ed8c6a4 100644 (file)
@@ -22,6 +22,7 @@ nobase_include_HEADERS = \
        xbt/graphxml.h \
        \
        xbt/synchro.h \
+       xbt/queue.h \
        \
        msg/msg.h \
        msg/datatypes.h \
index 63d7a27..761025c 100644 (file)
@@ -231,6 +231,7 @@ nobase_include_HEADERS = \
        xbt/graphxml.h \
        \
        xbt/synchro.h \
+       xbt/queue.h \
        \
        msg/msg.h \
        msg/datatypes.h \
diff --git a/include/xbt/queue.h b/include/xbt/queue.h
new file mode 100644 (file)
index 0000000..8412c3e
--- /dev/null
@@ -0,0 +1,47 @@
+/* $Id$ */
+
+/* A (synchronized) message queue.                                          */
+/* Popping an empty queue is blocking, as well as pushing a full one        */
+
+/* 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_QUEUE_H
+#define _XBT_QUEUE_H
+
+#include "xbt/misc.h" /* SG_BEGIN_DECL */
+//#include "xbt/function_types.h"
+
+SG_BEGIN_DECL()
+
+/** @addtogroup XBT_queue
+  * @brief Synchronized message exchanging queue.
+  *
+  * These is the classical producer/consumer synchronization scheme, which all concurrent programmer recode one day or another.
+  *  
+  * For performance concerns, the content of queue must be homogeneous, 
+  * just like dynars (see the \ref XBT_dynar section). Indeed, queues use a 
+  * dynar to store the data, and add the synchronization on top of it. 
+  * 
+  * @{
+  */
+
+  /** \brief Queue data type (opaque type) */
+  typedef struct s_xbt_queue_ *xbt_queue_t;
+
+
+  XBT_PUBLIC(xbt_queue_t)   xbt_queue_new(int capacity, unsigned long elm_size);
+  XBT_PUBLIC(void)          xbt_queue_free(xbt_queue_t *queue);
+
+  XBT_PUBLIC(unsigned long) xbt_queue_length(const xbt_queue_t queue);
+
+  XBT_PUBLIC(void) xbt_queue_push    (xbt_queue_t queue, const void *src);
+  XBT_PUBLIC(void) xbt_queue_pop     (xbt_queue_t queue, void *const dst);
+  XBT_PUBLIC(void) xbt_queue_unshift (xbt_queue_t queue, const void *src);
+  XBT_PUBLIC(void) xbt_queue_shift   (xbt_queue_t queue, void *const dst);
+
+SG_END_DECL()
+
+#endif /* _XBT_QUEUE_H */
index a99e461..3a57627 100644 (file)
@@ -127,8 +127,13 @@ XBT_SRC=\
   xbt/graph.c                                                                \
   xbt/set.c                                                                  \
   xbt/xbt_matrix.c                                                           \
+  \
+  xbt/queue.c                                                                \
+  \
   xbt/xbt_peer.c                                                             \
+  \
   xbt/xbt_main.c                                                             \
+  \
   xbt/config.c                                                               \
   xbt/cunit.c                                                                \
   xbt/graphxml_parse.c
index f54beca..837ae85 100644 (file)
@@ -80,8 +80,8 @@ am__objects_1 = snprintf.lo xbt_str.lo ex.lo xbt_virtu.lo sysdep.lo \
        xbt_log_layout_simple.lo xbt_log_layout_format.lo \
        mallocator.lo dynar.lo dict.lo dict_elm.lo dict_cursor.lo \
        dict_multi.lo heap.lo fifo.lo swag.lo graph.lo set.lo \
-       xbt_matrix.lo xbt_peer.lo xbt_main.lo config.lo cunit.lo \
-       graphxml_parse.lo
+       xbt_matrix.lo queue.lo xbt_peer.lo xbt_main.lo config.lo \
+       cunit.lo graphxml_parse.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
@@ -104,7 +104,7 @@ am__libsimgrid_la_SOURCES_DIST = xbt/snprintf.c xbt/xbt_str.c xbt/ex.c \
        xbt/xbt_log_layout_simple.c xbt/xbt_log_layout_format.c \
        xbt/mallocator.c xbt/dynar.c xbt/dict.c xbt/dict_elm.c \
        xbt/dict_cursor.c xbt/dict_multi.c xbt/heap.c xbt/fifo.c \
-       xbt/swag.c xbt/graph.c xbt/set.c xbt/xbt_matrix.c \
+       xbt/swag.c xbt/graph.c xbt/set.c xbt/xbt_matrix.c xbt/queue.c \
        xbt/xbt_peer.c xbt/xbt_main.c xbt/config.c xbt/cunit.c \
        xbt/graphxml_parse.c surf/maxmin.c surf/lagrange.c \
        surf/trace_mgr.c surf/surf.c surf/surfxml_parse.c surf/cpu.c \
@@ -167,20 +167,21 @@ am__libsimgrid4java_la_SOURCES_DIST = xbt/snprintf.c xbt/xbt_str.c \
        xbt/xbt_log_layout_format.c xbt/mallocator.c xbt/dynar.c \
        xbt/dict.c xbt/dict_elm.c xbt/dict_cursor.c xbt/dict_multi.c \
        xbt/heap.c xbt/fifo.c xbt/swag.c xbt/graph.c xbt/set.c \
-       xbt/xbt_matrix.c xbt/xbt_peer.c xbt/xbt_main.c xbt/config.c \
-       xbt/cunit.c xbt/graphxml_parse.c surf/maxmin.c surf/lagrange.c \
-       surf/trace_mgr.c surf/surf.c surf/surfxml_parse.c surf/cpu.c \
-       surf/network.c surf/workstation.c surf/surf_timer.c \
-       surf/network_dassf.c surf/workstation_KCCFLN05.c \
-       surf/gtnets/gtnets_simulator.cc surf/gtnets/gtnets_topology.cc \
-       surf/gtnets/gtnets_interface.cc surf/network_gtnets.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_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 \
+       xbt/xbt_matrix.c xbt/queue.c xbt/xbt_peer.c xbt/xbt_main.c \
+       xbt/config.c xbt/cunit.c xbt/graphxml_parse.c surf/maxmin.c \
+       surf/lagrange.c surf/trace_mgr.c surf/surf.c \
+       surf/surfxml_parse.c surf/cpu.c surf/network.c \
+       surf/workstation.c surf/surf_timer.c surf/network_dassf.c \
+       surf/workstation_KCCFLN05.c surf/gtnets/gtnets_simulator.cc \
+       surf/gtnets/gtnets_topology.cc surf/gtnets/gtnets_interface.cc \
+       surf/network_gtnets.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_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 \
        java/jmsg_parallel_task.h java/jmsg_process.c \
        java/jmsg_process.h java/jmsg_task.c java/jmsg_task.h \
        msg/msg_config.c msg/task.c msg/host.c msg/m_process.c \
@@ -488,8 +489,13 @@ XBT_SRC = \
   xbt/graph.c                                                                \
   xbt/set.c                                                                  \
   xbt/xbt_matrix.c                                                           \
+  \
+  xbt/queue.c                                                                \
+  \
   xbt/xbt_peer.c                                                             \
+  \
   xbt/xbt_main.c                                                             \
+  \
   xbt/config.c                                                               \
   xbt/cunit.c                                                                \
   xbt/graphxml_parse.c
@@ -799,6 +805,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/network_gtnets.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/peermanagement.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/process.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/queue.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rl_dns.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rl_emul.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rl_msg.Plo@am__quote@
@@ -1034,6 +1041,13 @@ xbt_matrix.lo: xbt/xbt_matrix.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 xbt_matrix.lo `test -f 'xbt/xbt_matrix.c' || echo '$(srcdir)/'`xbt/xbt_matrix.c
 
+queue.lo: xbt/queue.c
+@am__fastdepCC_TRUE@   $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT queue.lo -MD -MP -MF $(DEPDIR)/queue.Tpo -c -o queue.lo `test -f 'xbt/queue.c' || echo '$(srcdir)/'`xbt/queue.c
+@am__fastdepCC_TRUE@   mv -f $(DEPDIR)/queue.Tpo $(DEPDIR)/queue.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='xbt/queue.c' object='queue.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 queue.lo `test -f 'xbt/queue.c' || echo '$(srcdir)/'`xbt/queue.c
+
 xbt_peer.lo: xbt/xbt_peer.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_peer.lo -MD -MP -MF $(DEPDIR)/xbt_peer.Tpo -c -o xbt_peer.lo `test -f 'xbt/xbt_peer.c' || echo '$(srcdir)/'`xbt/xbt_peer.c
 @am__fastdepCC_TRUE@   mv -f $(DEPDIR)/xbt_peer.Tpo $(DEPDIR)/xbt_peer.Plo
diff --git a/src/xbt/queue.c b/src/xbt/queue.c
new file mode 100644 (file)
index 0000000..30c01e2
--- /dev/null
@@ -0,0 +1,134 @@
+/* $Id$ */
+
+/* A (synchronized) message queue.                                          */
+/* Popping an empty queue is blocking, as well as pushing a full one        */
+
+/* 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. */
+
+#include "xbt/misc.h"
+#include "xbt/sysdep.h"
+#include "xbt/log.h"
+//#include "xbt/ex.h"
+#include "xbt/dynar.h"
+
+#include "xbt/synchro.h"
+#include "xbt/queue.h" /* this module */
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_queue,xbt,"Message exchanging queue");
+
+typedef struct s_xbt_queue_ {
+   int capacity;
+   xbt_dynar_t data;
+   xbt_mutex_t mutex;
+   xbt_cond_t  not_full, not_empty;
+} s_xbt_queue_t;
+
+/** @brief Create a new message exchange queue.
+ * 
+ * @param capacity the capacity of the queue. If non-nul, any attempt to push an item which would let the size of the queue over this number will be blocking until someone else pop some data
+ * @param elm_size size of each element stored in it (see #xbt_dynar_new)
+ */
+xbt_queue_t xbt_queue_new(int capacity,unsigned long elm_size) {
+   xbt_queue_t res = xbt_new0(s_xbt_queue_t,1);
+   xbt_assert0(capacity>=0,"Capacity cannot be negative");
+
+   res->capacity = capacity;
+   res->data = xbt_dynar_new(elm_size,NULL);
+   res->mutex = xbt_mutex_init();
+   res->not_full = xbt_cond_init();
+   res->not_empty = xbt_cond_init();
+   return res;
+}
+/** @brief Destroy a message exchange queue.
+ *
+ * Any remaining content is leaked.
+ */
+void xbt_queue_free(xbt_queue_t *queue) {
+
+   xbt_dynar_free(&( (*queue)->data ));
+   xbt_mutex_destroy( (*queue)->mutex );
+   xbt_cond_destroy( (*queue)->not_full );
+   xbt_cond_destroy( (*queue)->not_empty );
+   free((*queue));
+   *queue = NULL;
+}
+
+/** @brief Get the queue size */
+unsigned long xbt_queue_length(xbt_queue_t queue) {
+   unsigned long res;
+   xbt_mutex_lock(queue->mutex);
+   res=xbt_dynar_length(queue->data);
+   xbt_mutex_unlock(queue->mutex);
+   return res;
+}
+
+/** @brief Push something to the message exchange queue.
+ * 
+ * This is blocking if the declared capacity is non-nul, and if this amount is reached.
+ * 
+ * @seealso #xbt_dynar_push
+ */
+void xbt_queue_push(xbt_queue_t queue, const void *src) {
+   xbt_mutex_lock(queue->mutex);
+   while (queue->capacity != 0 && queue->capacity == xbt_dynar_length(queue->data)) {
+      DEBUG2("Capacity of %p exceded (=%d). Waiting",queue,queue->capacity);
+      xbt_cond_wait(queue->not_full,queue->mutex);
+   }
+   xbt_dynar_push(queue->data,src);
+   xbt_cond_signal(queue->not_empty);
+}
+
+   
+/** @brief Pop something from the message exchange queue.
+ * 
+ * This is blocking if the queue is empty.
+ * 
+ * @seealso #xbt_dynar_pop
+ * 
+ */
+void xbt_queue_pop(xbt_queue_t queue, void* const dst) {
+   xbt_mutex_lock(queue->mutex);
+   while (xbt_dynar_length(queue->data) == 0) {
+      DEBUG1("Queue %p empty. Waiting",queue);
+      xbt_cond_wait(queue->not_empty,queue->mutex);
+   }
+   xbt_dynar_pop(queue->data,dst);
+   xbt_cond_signal(queue->not_full);
+}
+
+/** @brief Unshift something to the message exchange queue.
+ * 
+ * This is blocking if the declared capacity is non-nul, and if this amount is reached.
+ * 
+ * @seealso #xbt_dynar_unshift
+ */
+void xbt_queue_unshift(xbt_queue_t queue, const void *src) {
+   xbt_mutex_lock(queue->mutex);
+   while (queue->capacity != 0 && queue->capacity == xbt_dynar_length(queue->data)) {
+      DEBUG2("Capacity of %p exceded (=%d). Waiting",queue,queue->capacity);
+      xbt_cond_wait(queue->not_full,queue->mutex);
+   }
+   xbt_dynar_unshift(queue->data,src);
+   xbt_cond_signal(queue->not_empty);
+}
+   
+
+/** @brief Shift something from the message exchange queue.
+ * 
+ * This is blocking if the queue is empty.
+ * 
+ * @seealso #xbt_dynar_shift
+ * 
+ */
+void xbt_queue_shift(xbt_queue_t queue, void* const dst) {
+   xbt_mutex_lock(queue->mutex);
+   while (xbt_dynar_length(queue->data) == 0) {
+      DEBUG1("Queue %p empty. Waiting",queue);
+      xbt_cond_wait(queue->not_empty,queue->mutex);
+   }
+   xbt_dynar_shift(queue->data,dst);
+   xbt_cond_signal(queue->not_full);
+}