This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Fix / clean-up config vs crosses (4/n) + librt improvements


Hi,

the below first moves GLIBCXX_CHECK_GETTIMEOFDAY to the set of checks in common between native and crosses, by changing it to use GCC_TRY_COMPILE_OR_LINK.

Less trivially, it also changes GLIBCXX_CHECK_CLOCK_GETTIME to a flexible configure-time option, [no] be default because in general it requires TRY_LINK tests, but with the possibility of searching libposix4 and also librt. The latter seems to me a good improvement, because the default on many common platforms (e.g., linux) is the same (no clock_gettime facilities), but in case of need, if the user knows what is doing, all the available clocks can be easily configured and made available to the <chrono> implementation.

Tested x86_64-linux various ways... Committed to mainline.

Paolo.

//////////////////
2008-08-23  Paolo Carlini  <paolo.carlini@oracle.com>

	* acinclude.m4 ([GLIBCXX_CHECK_GETTIMEOFDAY]): Change to use
	GCC_TRY_COMPILE_OR_LINK.
	([GLIBCXX_CHECK_CLOCK_GETTIME]): Rename to
	[GLIBCXX_ENABLE_CLOCK_GETTIME], a versatile configure-time option,
	[no] by default, since it includes TRY_LINK checks.  librt is also
	searched, if requested.
	* doc/xml/manual/configure.xml: Document the latter.
	* configure.ac: Move the above checks outside native-only.
	* configure: Regenerate.
Index: configure.ac
===================================================================
*** configure.ac	(revision 139508)
--- configure.ac	(working copy)
*************** GLIBCXX_CHECK_C99_TR1
*** 143,148 ****
--- 143,155 ----
  # For common values of EOF, SEEK_CUR, SEEK_END.
  GLIBCXX_CHECK_STDIO_MACROS
  
+ # For gettimeofday support.
+ GLIBCXX_CHECK_GETTIMEOFDAY
+ 
+ # For clock_gettime support.
+ # NB: The default is [no], because otherwise it requires linking.
+ GLIBCXX_ENABLE_CLOCK_GETTIME([no])
+ 
  AC_LC_MESSAGES
  
  # Check for available headers.
*************** if $GLIBCXX_IS_NATIVE; then
*** 167,178 ****
    # For dev/random and dev/urandom for TR1.
    GLIBCXX_CHECK_RANDOM_TR1
  
-   # For clock_gettime support.
-   GLIBCXX_CHECK_CLOCK_GETTIME
- 
-   # For gettimeofday support.
-   GLIBCXX_CHECK_GETTIMEOFDAY
- 
    # For TLS support.
    GCC_CHECK_TLS
  
--- 174,179 ----
Index: doc/xml/manual/configure.xml
===================================================================
*** doc/xml/manual/configure.xml	(revision 139508)
--- doc/xml/manual/configure.xml	(working copy)
***************
*** 312,318 ****
       environment.
       </para>
   </listitem></varlistentry>
- </variablelist>
  
  
  </sect1>
\ No newline at end of file
--- 312,338 ----
       environment.
       </para>
   </listitem></varlistentry>
  
+  <varlistentry><term><code>--enable-clock-gettime</code></term>
+  <listitem><para>This is an abbreviated form of
+         <code>'--enable-clock-gettime=yes'</code>(described next).
+      </para>
+  </listitem></varlistentry>
+ 
+  <varlistentry><term><code>--enable-clock-gettime=OPTION</code></term>
+  <listitem><para>Enables checks (link-type too) for the clock_gettime clocks,
+         used in the implementation [time.clock] in the current C++0x draft.
+         The choice OPTION=yes checks for the availability of the monotonic and
+         realtime clocks in libc and libposix4.  OPTION=rt searches librt too,
+         and in case of success enables its linking to libstdc++ as part of the
+         build process.   Note that this is not always desirable because, in
+         glibc, for example, in turn it triggers automatically the linking of
+         libpthread too, which activates locking, a large overhead for
+         single-thread programs.  OPTION=no skips the tests completely.  The
+         default is OPTION=no.
+     </para>
+  </listitem></varlistentry>
+ 
+ </variablelist>
  
  </sect1>
\ No newline at end of file
Index: acinclude.m4
===================================================================
*** acinclude.m4	(revision 139508)
--- acinclude.m4	(working copy)
*************** AC_DEFUN([GLIBCXX_ENABLE_C99], [
*** 1074,1083 ****
  
  
  dnl
! dnl Check for IEEE Std 1003.1-2001 clock_gettime required for 
! dnl 20.8.5 [time.clock] in the current C++0X working draft.
  dnl
! AC_DEFUN([GLIBCXX_CHECK_CLOCK_GETTIME], [
  
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
--- 1074,1102 ----
  
  
  dnl
! dnl Check for clock_gettime clocks, used in the implementation of 20.8.5
! dnl [time.clock] in the current C++0x working draft.
  dnl
! dnl --enable-clock-gettime
! dnl --enable-clock-gettime=yes
! dnl        checks for the availability of monotonic or realtime clocks
! dnl        in libc and libposix4
! dnl --enable-clock-gettime=rt
! dnl        searches librt too, and in case of success enables its linking
! dnl        to libstdc++ as part of the build process.   Note that this is
! dnl        not always desirable because, in glibc, for example, in turn it
! dnl        triggers automatically the linking of libpthread too, which
! dnl        activates locking, a large overhead for single-thread programs.
! dnl --enable-clock-gettime=no
! dnl --disable-clock-gettime
! dnl        disables the checks completely
! dnl
! AC_DEFUN([GLIBCXX_ENABLE_CLOCK_GETTIME], [
! 
!   AC_MSG_CHECKING([for clock_gettime clocks])					 
!   GLIBCXX_ENABLE(clock-gettime,$1,,
!     [use KIND for check type],
!     [permit yes|no|rt])
  
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
*************** AC_DEFUN([GLIBCXX_CHECK_CLOCK_GETTIME],
*** 1085,1129 ****
    CXXFLAGS="$CXXFLAGS -fno-exceptions"
    ac_save_LIBS="$LIBS"
  
!   AC_SEARCH_LIBS(clock_gettime, [posix4])
  
!   # Link to -lposix4.
!   case "$ac_cv_search_clock_gettime" in
!     -lposix4*) GLIBCXX_LIBS=$ac_cv_search_clock_gettime
!   esac
  
!   AC_CHECK_HEADERS(unistd.h, ac_has_unistd_h=yes, ac_has_unistd_h=no)
!   
!   ac_has_clock_monotonic=no;  
!   ac_has_clock_realtime=no;  
!   if test x"$ac_has_unistd_h" = x"yes"; then    
!     AC_MSG_CHECKING([for monotonic clock])
!     AC_TRY_LINK(
!       [#include <unistd.h>
!        #include <time.h>
!       ],
!       [#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
!         timespec tp;     
!        #endif
!         clock_gettime(CLOCK_MONOTONIC, &tp);
!       ], [ac_has_clock_monotonic=yes], [ac_has_clock_monotonic=no])
!     
!     AC_MSG_RESULT($ac_has_clock_monotonic)   
!     
!     AC_MSG_CHECKING([for realtime clock])
!     AC_TRY_LINK(
!       [#include <unistd.h>
!        #include <time.h>
!       ],
!       [#if _POSIX_TIMERS > 0
!         timespec tp;      
!        #endif
!         clock_gettime(CLOCK_REALTIME, &tp);
!       ], [ac_has_clock_realtime=yes], [ac_has_clock_realtime=no])
      
!     AC_MSG_RESULT($ac_has_clock_realtime)
!   fi 
!   
    if test x"$ac_has_clock_monotonic" = x"yes"; then
      AC_DEFINE(_GLIBCXX_USE_CLOCK_MONOTONIC, 1,
        [ Defined if clock_gettime has monotonic clock support. ])
--- 1104,1156 ----
    CXXFLAGS="$CXXFLAGS -fno-exceptions"
    ac_save_LIBS="$LIBS"
  
!   ac_has_clock_monotonic=no;  
!   ac_has_clock_realtime=no;
  
!   if test x"$enable_clock_gettime" != x"no"; then
  
!     if test x"$enable_clock_gettime" = x"rt"; then
!       AC_SEARCH_LIBS(clock_gettime, [rt posix4])
!     else
!       AC_SEARCH_LIBS(clock_gettime, [posix4])
!     fi
! 
!     case "$ac_cv_search_clock_gettime" in
!       -l*) GLIBCXX_LIBS=$ac_cv_search_clock_gettime
!     esac
! 
!     AC_CHECK_HEADERS(unistd.h, ac_has_unistd_h=yes, ac_has_unistd_h=no)
! 
!     if test x"$ac_has_unistd_h" = x"yes"; then
!       AC_MSG_CHECKING([for monotonic clock])
!       AC_TRY_LINK(
!         [#include <unistd.h>
!          #include <time.h>
!         ],
!         [#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
!           timespec tp;     
!          #endif
!           clock_gettime(CLOCK_MONOTONIC, &tp);
!         ], [ac_has_clock_monotonic=yes], [ac_has_clock_monotonic=no])
! 
!       AC_MSG_RESULT($ac_has_clock_monotonic)   
      
!       AC_MSG_CHECKING([for realtime clock])
!       AC_TRY_LINK(
!         [#include <unistd.h>
!          #include <time.h>
!         ],
!         [#if _POSIX_TIMERS > 0
!           timespec tp;      
!          #endif
!           clock_gettime(CLOCK_REALTIME, &tp);
!         ], [ac_has_clock_realtime=yes], [ac_has_clock_realtime=no])
! 
!       AC_MSG_RESULT($ac_has_clock_realtime)
!     fi
! 
!   fi
! 
    if test x"$ac_has_clock_monotonic" = x"yes"; then
      AC_DEFINE(_GLIBCXX_USE_CLOCK_MONOTONIC, 1,
        [ Defined if clock_gettime has monotonic clock support. ])
*************** AC_DEFUN([GLIBCXX_CHECK_CLOCK_GETTIME],
*** 1142,1152 ****
  ])
  
  dnl
! dnl Check for IEEE Std 1003.1-2001 gettimeofday required for 
! dnl 20.8.5 [time.clock] in the current C++0X working draft.
  dnl
  AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [
    
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
    ac_save_CXXFLAGS="$CXXFLAGS"
--- 1169,1181 ----
  ])
  
  dnl
! dnl Check for gettimeofday, used in the implementation of 20.8.5
! dnl [time.clock] in the current C++0x working draft.
  dnl
  AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [
    
+   AC_MSG_CHECKING([for gettimeofday])
+ 
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
    ac_save_CXXFLAGS="$CXXFLAGS"
*************** AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [
*** 1156,1162 ****
    AC_CHECK_HEADERS(sys/time.h, ac_has_sys_time_h=yes, ac_has_sys_time_h=no)
    if test x"$ac_has_sys_time_h" = x"yes"; then
      AC_MSG_CHECKING([for gettimeofday])
!     AC_TRY_LINK([#include <sys/time.h>],
        [timeval tv; gettimeofday(&tv, 0);],
        [ac_has_gettimeofday=yes], [ac_has_gettimeofday=no])
      
--- 1185,1191 ----
    AC_CHECK_HEADERS(sys/time.h, ac_has_sys_time_h=yes, ac_has_sys_time_h=no)
    if test x"$ac_has_sys_time_h" = x"yes"; then
      AC_MSG_CHECKING([for gettimeofday])
!     GCC_TRY_COMPILE_OR_LINK([#include <sys/time.h>],
        [timeval tv; gettimeofday(&tv, 0);],
        [ac_has_gettimeofday=yes], [ac_has_gettimeofday=no])
      

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]