Changeset 19897

Show
Ignore:
Timestamp:
04/05/07 16:54:02 (2 years ago)
Author:
patrick
Message:

Added thread start/exit notification capabilities. It is now possible to
register callbacks that are invoked whenever a new thread starts its
execution (invoked just before the user-supplied thread functor starts) and
after a thread completes its execution (invoked just after the thread functor
returns). This is implemented using Boost.Signals for reasons outlined in a
post that I made to the vrjuggler-devel mailing list.

Bumped version to 1.1.44.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/vapor/ChangeLog

    r19849 r19897  
    11DATE       AUTHOR   CHANGE 
    22---------- -------- ----------------------------------------------------------- 
     32007-04-05 patrick  Added thread start/exit notification signals. Boost.Signals 
     4                    is now a required dependency. 
     5                    NEW VERSION: 1.1.44 
    362007-03-03 patrick  Allow callers of vpr::InetAddr::getAllLocalAddrs() to 
    47                    indicate whether interfaces in the down state should be 
  • juggler/trunk/modules/vapor/Makefile.inc.in

    r19729 r19897  
    374374          $(topdir)/boost_filesystem.fpc                                \ 
    375375          $(libdir)$(LIBBITSUF)/flagpoll/boost_filesystem-$(BOOST_VERSION).$(ISA).fpc 
     376        $(INSTALL) -m $(FILE_PERMS) $(GROUP_OPT_UNIX)                   \ 
     377          $(topdir)/boost_signals.fpc                                   \ 
     378          $(libdir)$(LIBBITSUF)/flagpoll/boost_signals-$(BOOST_VERSION).$(ISA).fpc 
    376379ifeq ($(USE_NSPR), Y) 
    377380        $(INSTALL) -m $(FILE_PERMS) $(GROUP_OPT_UNIX)                   \ 
  • juggler/trunk/modules/vapor/Makefile.pre.in

    r19729 r19897  
    6363boost.fpc.in: ; 
    6464boost_filesystem.fpc.in: ; 
     65boost_signals.fpc.in: ; 
    6566$(M4_DEPS): ; 
    6667$(srcdir)/VERSION: ; 
     
    7374Makefile: $(srcdir)/VERSION configure config.status Makefile.in         \ 
    7475          Makefile.inc.in make.defs.mk.in vpr.fpc.in boost.fpc.in       \ 
    75           boost_filesystem.fpc.in 
     76          boost_filesystem.fpc.in boost_signals.fpc.in 
    7677        $(CFG_SHELL) $(srcdir)/configure $(CONFIGURE_ARGS) 
    7778        @$(MAKE) -f Makefile cleandepend 
  • juggler/trunk/modules/vapor/VERSION

    r19849 r19897  
     11.1.44-0 @04/05/2007 21:55:00 UTC@ 
    121.1.43-0 @03/03/2007 17:10:00 UTC@ 
    231.1.42-0 @03/02/2007 17:55:00 UTC@ 
  • juggler/trunk/modules/vapor/boost_signals.fpc.in

    r19450 r19897  
    33 
    44# Standard Flagpoll Variables 
    5 Name: Boost.Filesystem 
    6 Description: The Boost.Filesystem Library provides portable facilities to query and manipulate paths, files, and directories
    7 URL: http://www.boost.org/libs/filesystem/doc/index.htm 
     5Name: Boost.Signals 
     6Description: The Boost.Signals library is an implementation of a managed signals and slots system
     7URL: http://www.boost.org/doc/html/signals.html 
    88Version: @BOOST_VERSION_DOT@ 
    9 Provides: Boost.Filesystem boost.filesystem 
     9Provides: Boost.Signals boost.signals 
    1010Requires: boost = @BOOST_VERSION_DOT@ 
    1111Arch: @ISA@ 
    1212Cflags: @BOOST_INCLUDES@ 
    13 Libs: -L@BOOST_LIBDIR@ -l@boost_fs_name@ 
     13Libs: -L@BOOST_LIBDIR@ -l@boost_signals_name@ 
  • juggler/trunk/modules/vapor/configure.ac

    r19745 r19897  
    145145            [given_boost_fs_libname="$withval"], [given_boost_fs_libname='']) 
    146146 
     147AC_ARG_WITH([boost-signals-lib], 
     148            [  --with-boost-signals-lib=<LIB NAME> 
     149                          The name of the Boost.Signals 
     150                          library suitable for the -l 
     151                          compiler option                 [default=Auto-detect]], 
     152            [given_boost_signals_libname="$withval"], [given_boost_signals_libname='']) 
     153 
    147154# ----------------------------------------------------------------------------- 
    148155# System-dependent stuff. 
     
    618625fi 
    619626 
    620 # Construct the Boost.Filesystem library name automatically based on Boost 
    621 # naming conventions if the user did not provide a library name. 
    622 if test "x$given_boost_fs_libname" = "x" ; then 
    623    case $CC in 
    624       gcc*|*/gcc*) 
     627# Build up the possible Boost library suffix names. These will be stored in 
     628# $boost_suffixes and used later as necessary. 
     629case $CC in 
     630   gcc*|*/gcc*) 
     631      toolset='-gcc' 
     632      ;; 
     633   icc*|*/icc*) 
     634      if test "x$OS_TYPE" = "xWin32" ; then 
     635         toolset='-iw' 
     636      else 
     637         toolset='-il' 
     638      fi 
     639      ;; 
     640   cygcl|msvccc|cl*|CL*) 
     641      toolset="-${BOOST_TOOL:=vc7}" 
     642      ;; 
     643   cc*|*/cc*) 
     644      if test "x$GCC" = "xyes" ; then 
    625645         toolset='-gcc' 
    626          ;; 
    627       icc*|*/icc*) 
    628          if test "x$OS_TYPE" = "xWin32" ; then 
    629             toolset='-iw' 
    630          else 
    631             toolset='-il' 
    632          fi 
    633          ;; 
    634       cygcl|msvccc|cl*|CL*) 
    635          toolset="-${BOOST_TOOL:=vc7}" 
    636          ;; 
    637       cc*|*/cc*) 
    638          if test "x$GCC" = "xyes" ; then 
    639             toolset='-gcc' 
    640          else 
    641             case $PLATFORM in 
    642                IRIX) 
    643                   toolset='-mp' 
    644                   ;; 
    645                Solaris) 
    646                   toolset='-sw' 
    647                   ;; 
    648             esac 
    649          fi 
    650          ;; 
    651    esac 
    652  
    653    # A correct installation of Boost on Darwin does not include the toolset name 
    654    # as part of the library file name. 
    655    if test "x$PLATFORM" = "xDarwin" ; then 
    656       toolset='' 
    657       threading='' 
    658    else 
    659       # We can only use multi-threading versions of Boost libraries if we are 
    660       # not using SPROC threads.  Boost does not support SPROC. 
    661       if test "x$SUBSYSTEM" != "xSPROC" -a "x$ABI" != "x64" ; then 
    662          threading='-mt' 
     646      else 
     647         case $PLATFORM in 
     648            IRIX) 
     649               toolset='-mp' 
     650               ;; 
     651            Solaris) 
     652               toolset='-sw' 
     653               ;; 
     654         esac 
    663655      fi 
     656      ;; 
     657esac 
     658 
     659# A correct installation of Boost on Darwin does not include the toolset name 
     660# as part of the library file name. 
     661if test "x$PLATFORM" = "xDarwin" ; then 
     662   toolset='' 
     663   threading='' 
     664else 
     665   # We can only use multi-threading versions of Boost libraries if we are 
     666   # not using SPROC threads.  Boost does not support SPROC. 
     667   if test "x$SUBSYSTEM" != "xSPROC" -a "x$ABI" != "x64" ; then 
     668      threading='-mt' 
    664669   fi 
    665  
    666    boost_suffixes="$toolset$threading-$BOOST_LIB_VERSION $toolset$threading $threading" 
    667 else 
     670fi 
     671 
     672boost_suffixes="$toolset$threading-$BOOST_LIB_VERSION $toolset$threading $threading" 
     673 
     674if test "x$given_boost_fs_libname" != "x" ; then 
    668675   boost_fs_name="$given_boost_fs_libname" 
     676fi 
     677 
     678if test "x$given_boost_signals_libname" != "x" ; then 
     679   boost_signals_name="$given_boost_signals_libname" 
    669680fi 
    670681 
     
    733744done 
    734745 
    735 DPP_LANG_RESTORE 
    736  
    737746if test "x$vpr_have_boost_fs" != "xyes" ; then 
    738747   AC_MSG_ERROR([*** Boost.Filesystem required by VPR ***]) 
    739748fi 
     749 
     750testBoostSignals ( ) 
     751{ 
     752   libname="$1" 
     753   orig_LIBS="$2" 
     754 
     755   # NOTE: We do not need $ABI_FLAGS in $LDFLAGS since $CXXFLAGS and $LDFLAGS 
     756   # are used together by AC_TRY_LINK(). 
     757   LIBS="-l$libname $orig_LIBS" 
     758 
     759   AC_MSG_CHECKING([for boost::signal::operator()() in $libname]) 
     760   AC_TRY_LINK([#include <boost/signal.hpp>], 
     761               [boost::signal<void ()> s; s();], 
     762               [vpr_have_boost_signals='yes'], [vpr_have_boost_signals='no']) 
     763   rm -rf ./ii_files 
     764   AC_MSG_RESULT([$vpr_have_boost_signals]) 
     765 
     766   LIBS="$orig_LIBS" 
     767} 
     768 
     769LDFLAGS="-L$BOOST_LIBDIR $vprsave_LDFLAGS" 
     770 
     771if test "x$boost_signals_name" != "x" ; then 
     772   testBoostSignals $boost_signals_name $vprsave_LIBS 
     773else 
     774   # The extra empty string is to allow for no suffix to be used on the 
     775   # boost_signals library name. 
     776   for s in $boost_suffixes "" ; do 
     777      cur_boost_signals_name="boost_signals$s" 
     778 
     779      testBoostSignals $cur_boost_signals_name $vprsave_LIBS 
     780 
     781      if test "$vpr_have_boost_signals" = "yes" ; then 
     782         boost_signals_name="$cur_boost_signals_name" 
     783         break 
     784      fi 
     785   done 
     786fi 
     787 
     788if test "x$vpr_have_boost_signals" != "xyes" ; then 
     789   AC_MSG_ERROR([*** Boost.Signals required by VPR ***]) 
     790fi 
     791 
     792DPP_LANG_RESTORE 
    740793 
    741794CXXFLAGS="$vprsave_CXXFLAGS" 
     
    909962# Put together the basic information needed to compile VPR applications. 
    910963if test "x$OS_TYPE" = "xWin32" ; then 
    911     APP_EXTRA_LIBS="$LDFLAGS $LIBS $CPPDOM_LDFLAGS $CPPDOM_LIBS $BOOST_LDFLAGS_LINK_EXE $boost_fs_name.lib $NSPR_LDFLAGS_LINK_EXE $NSPR_LIB_LINK_EXE $PLC_LIB_LINK_EXE ws2_32.lib" 
     964    APP_EXTRA_LIBS="$LDFLAGS $LIBS $CPPDOM_LDFLAGS $CPPDOM_LIBS $BOOST_LDFLAGS_LINK_EXE $boost_signals_name.lib $boost_fs_name.lib $NSPR_LDFLAGS_LINK_EXE $NSPR_LIB_LINK_EXE $PLC_LIB_LINK_EXE ws2_32.lib" 
    912965else 
    913     APP_EXTRA_LIBS="$LDFLAGS $CPPDOM_LDFLAGS $CPPDOM_LIBS $BOOST_LDFLAGS -l$boost_fs_name $PTHREAD_ARG $LIBS $NSPR_LDFLAGS $NSPR_LIB $PLC_LIB $PTHREAD_LIB $SEM_LIB $SOCKET_LIB $NS_LIB $UUID_LIB $DYN_LOAD_LIB" 
     966    APP_EXTRA_LIBS="$LDFLAGS $CPPDOM_LDFLAGS $CPPDOM_LIBS $BOOST_LDFLAGS -l$boost_signals_name -l$boost_fs_name $PTHREAD_ARG $LIBS $NSPR_LDFLAGS $NSPR_LIB $PLC_LIB $PTHREAD_LIB $SEM_LIB $SOCKET_LIB $NS_LIB $UUID_LIB $DYN_LOAD_LIB" 
    914967fi 
    915968 
     
    9531006# Dependencies for dynamic/shared libraries. 
    9541007if test "x$OS_TYPE" = "xWin32" ; then 
    955     DYLIB_DEPS="$CPPDOM_LDFLAGS $CPPDOM_LIBS $BOOST_LDFLAGS_LINK_EXE $boost_fs_name.lib $NSPR_LDFLAGS_LINK_EXE $NSPR_LIB_LINK_EXE $PLC_LIB_LINK_EXE ws2_32.lib" 
     1008    DYLIB_DEPS="$CPPDOM_LDFLAGS $CPPDOM_LIBS $BOOST_LDFLAGS_LINK_EXE $boost_signals_name.lib $boost_fs_name.lib $NSPR_LDFLAGS_LINK_EXE $NSPR_LIB_LINK_EXE $PLC_LIB_LINK_EXE ws2_32.lib" 
    9561009else 
    9571010    DYLIB_DEPS="$APP_EXTRA_LIBS" 
     
    10781131AC_SUBST(BOOST_LIBDIR) 
    10791132AC_SUBST(boost_fs_name) 
     1133AC_SUBST(boost_signals_name) 
    10801134AC_SUBST(subsystem_cxxflags) 
    10811135AC_SUBST(subsystem_libs) 
     
    11001154   boost.fpc 
    11011155   boost_filesystem.fpc 
     1156   boost_signals.fpc 
    11021157   nspr.fpc 
    11031158   vpr.fpc 
  • juggler/trunk/modules/vapor/vpr.fpc.in

    r19464 r19897  
    6565Version: ${vpr_version} 
    6666Provides: vpr VPR 
    67 Requires: Boost.Filesystem = @BOOST_VERSION_DOT@ boost >= @BOOST_VERSION_DOT@ cppdom = @CPPDOM_VERSION@ ${extra_deps} 
     67Requires: Boost.Signals = @BOOST_VERSION_DOT@ Boost.Filesystem = @BOOST_VERSION_DOT@ boost >= @BOOST_VERSION_DOT@ cppdom = @CPPDOM_VERSION@ ${extra_deps} 
    6868Arch: ${ISA} 
    6969Cflags: ${vpr_cxxflags} ${vpr_extra_cxxflags} ${subsystem_cxxflags} -I${includedir} ${ABI_FLAGS} 
  • juggler/trunk/modules/vapor/vpr/Thread/BaseThread.cpp

    r19729 r19897  
    3636#include <vpr/vprConfig.h> 
    3737 
    38 #include <vpr/Thread/BaseThread.h> 
     38#include <iomanip> 
     39 
     40#include <vpr/Sync/Guard.h> 
    3941#include <vpr/Thread/Thread.h> 
    4042#include <vpr/Thread/ThreadManager.h> 
    41 #include <iomanip> 
     43#include <vpr/Thread/BaseThread.h> 
     44 
    4245 
    4346namespace vpr 
    4447{ 
    4548 
     49BaseThread::state_signal_t BaseThread::sStartSignal; 
     50BaseThread::state_signal_t BaseThread::sExitSignal; 
     51vpr::Mutex sStartSignalLock; 
     52vpr::Mutex sExitSignalLock; 
     53 
    4654vpr::Int32 BaseThread::mNextThreadId = 0; 
    4755vpr::TSTable BaseThread::gTSTable; 
     56 
     57boost::signals::connection BaseThread:: 
     58addThreadStartCallback(BaseThread::state_signal_t::slot_function_type slot) 
     59{ 
     60   vpr::Guard<vpr::Mutex> g(sStartSignalLock); 
     61   return sStartSignal.connect(slot); 
     62} 
     63 
     64boost::signals::connection BaseThread:: 
     65addThreadExitCallback(BaseThread::state_signal_t::slot_function_type slot) 
     66{ 
     67   vpr::Guard<vpr::Mutex> g(sExitSignalLock); 
     68   return sExitSignal.connect(slot); 
     69} 
    4870 
    4971/** 
  • juggler/trunk/modules/vapor/vpr/Thread/BaseThread.h

    r19825 r19897  
    4040 
    4141#include <boost/function.hpp> 
     42#include <boost/signal.hpp> 
    4243#include <vpr/vprTypes.h> 
    4344#include <vpr/Thread/TSTable.h>            /* Needed to cache a copy here */ 
     45 
    4446 
    4547namespace vpr 
     
    6466class VPR_CLASS_API BaseThread 
    6567{ 
     68public: 
     69   /** @name Thread State Callback Handling */ 
     70   //@{ 
     71   /** 
     72    * The type for the thread start and exit signals. 
     73    * 
     74    * @since 1.1.44 
     75    */ 
     76   typedef boost::signal<void (vpr::Thread*)> state_signal_t; 
     77 
     78   /** 
     79    * Connects the given slot to the signal emitted whenever a new thread 
     80    * begins its execution. The slot is invoked immediately before the thread 
     81    * functor is invoked. 
     82    * 
     83    * @post \p slot is connected to \c sStartSignal. 
     84    * 
     85    * @param slot The slot object to be connected to the thread start signal. 
     86    * 
     87    * @return The connection object that holds the association between the 
     88    *         start signal and the given slot. 
     89    * 
     90    * @since 1.1.44 
     91    */ 
     92   static boost::signals::connection 
     93      addThreadStartCallback(state_signal_t::slot_function_type slot); 
     94 
     95   /** 
     96    * Connects the given slot to the signal emitted whenever a running thread 
     97    * completes its execution. The slot is invoked immediately after the 
     98    * thread functor returns. 
     99    * 
     100    * @post \p slot is connected to \c sExitSignal. 
     101    * 
     102    * @param slot The slot object to be connected to the thread exit signal. 
     103    * 
     104    * @return The connection object that holds the association between the 
     105    *         exit signal and the given slot. 
     106    * 
     107    * @since 1.1.44 
     108    */ 
     109   static boost::signals::connection 
     110      addThreadExitCallback(state_signal_t::slot_function_type slot); 
     111   //@} 
     112 
     113protected: 
     114   /** 
     115    * Emits the thread start signal. 
     116    * 
     117    * @since 1.1.44 
     118    */ 
     119   static void emitThreadStart(vpr::Thread* thread) 
     120   { 
     121      sStartSignal(thread); 
     122   } 
     123 
     124   /** 
     125    * Emits the thread exit signal. 
     126    * 
     127    * @since 1.1.44 
     128    */ 
     129   static void emitThreadExit(vpr::Thread* thread) 
     130   { 
     131      sExitSignal(thread); 
     132   } 
     133 
     134private: 
     135   static state_signal_t sStartSignal; 
     136   static state_signal_t sExitSignal; 
     137 
    66138public: 
    67139   enum VPRThreadPriority 
  • juggler/trunk/modules/vapor/vpr/md/NSPR/Thread/ThreadNSPR.cpp

    r19729 r19897  
    247247   try 
    248248   { 
     249      emitThreadStart(this); 
     250 
    249251      // --- CALL USER FUNCTOR --- // 
    250252      mUserThreadFunctor(); 
     253 
     254      emitThreadExit(this); 
    251255   } 
    252256   catch (std::exception& ex) 
  • juggler/trunk/modules/vapor/vpr/md/POSIX/Thread/ThreadPosix.cpp

    r19729 r19897  
    276276   try 
    277277   { 
     278      emitThreadStart(this); 
     279 
    278280      // --- CALL USER FUNCTOR --- // 
    279281      mUserThreadFunctor(); 
     282 
     283      emitThreadExit(this); 
    280284   } 
    281285   catch (std::exception& ex) 
  • juggler/trunk/modules/vapor/vpr/md/WIN32/Thread/ThreadWin32.cpp

    r19729 r19897  
    219219   try 
    220220   { 
     221      emitThreadStart(this); 
     222 
    221223      // --- CALL USER FUNCTOR --- // 
    222224      mUserThreadFunctor(); 
     225 
     226      emitThreadExit(this); 
    223227   } 
    224228   catch (std::exception& ex)