From patchwork Wed May 22 08:14:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 245567 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 601112C0096 for ; Wed, 22 May 2013 18:14:48 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=qRbhLpQ3EddEtR4OtpppfVK9cD6hmO6ugbdUvrE8y48hlJ izpejcksibwRwzIETllnhq9DFK491Mdc2Ecs6VSCPFrf0KDLn7W8Q0o5LK1fOnGf AkM4lkWh/+Ky4CZ2PA/nXkih4UV8R+hPYi+0YbES5n4NXeLo0alPFdHNWngs0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=g4kvk3qQE14D2170sahPoVwTqe8=; b=SpMEk/wbYJ+RIFXoQ3EH xa01BFKzQ36xkxlLNZnNbQwcqzab/bM/8r8K5n8jTh0yiXVXdlXAn9n0LoNTn2b0 iYSkE6ONGHpztgEDyDTK9Qp1/i4rVAYeC+R0tK5ctsZ2XWLKfe5X5sw9WSy+U4B6 D5pcEGqRZmEB1vQphzRdeGs= Received: (qmail 25869 invoked by alias); 22 May 2013 08:14:42 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 25842 invoked by uid 89); 22 May 2013 08:14:41 -0000 X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, SPF_PASS, TW_CX, TW_DC autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from mail-la0-f50.google.com (HELO mail-la0-f50.google.com) (209.85.215.50) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 22 May 2013 08:14:40 +0000 Received: by mail-la0-f50.google.com with SMTP id ed20so1615580lab.23 for ; Wed, 22 May 2013 01:14:37 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.145.199 with SMTP id sw7mr3421598lbb.131.1369210477859; Wed, 22 May 2013 01:14:37 -0700 (PDT) Received: by 10.112.210.2 with HTTP; Wed, 22 May 2013 01:14:37 -0700 (PDT) Date: Wed, 22 May 2013 09:14:37 +0100 Message-ID: Subject: [patch] Default to --enable-libstdcxx-time=auto From: Jonathan Wakely To: "libstdc++" , gcc-patches X-Virus-Found: No This alters the configure script to enable C++11 thread library features based on targets that are known to support the features, rather than based on link tests which are disabled by default. With Glibc 2.17 this enables a nanosecond resolution std::system_clock in the default configuration, yay! I've tested this on two versions of Fedora and Debian, but would be grateful for test results on Solaris, Cygwin and BSD targets, and for cross-compilers to any of those targets. * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Add KIND=auto to enable features if target OS is known to support them. * configure.ac (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Default to 'auto'. * configure: Regenerate. Tested x86_64-linux, committed to trunk. commit 47e011c33d78a00015265be39f2845209eeb97fc Author: Jonathan Wakely Date: Sun Feb 3 20:45:51 2013 +0000 * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Add KIND=auto to enable features if target OS is known to support them. * configure.ac (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Default to 'auto'. * configure: Regenerate. diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 619fff0..efeb6d4 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -871,7 +871,8 @@ dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING) dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, permit a|b|c) dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, SHELL-CODE-HANDLER) dnl -dnl See docs/html/17_intro/configury.html#enable for documentation. +dnl See manual/appendix_porting.html#appendix.porting.build_hacking for +dnl documentation. dnl m4_define([GLIBCXX_ENABLE],[dnl m4_define([_g_switch],[--enable-$1])dnl @@ -1161,8 +1162,9 @@ dnl nanosleep and sched_yield in libc and libposix4 and, if needed, dnl links in the latter. dnl --enable-libstdcxx-time=rt dnl also searches (and, if needed, links) librt. Note that this is -dnl not always desirable because, in glibc, for example, in turn it -dnl triggers the linking of libpthread too, which activates locking, +dnl not always desirable because, in glibc 2.16 and earlier, for +dnl example, in turn it triggers the linking of libpthread too, +dnl which activates locking, dnl a large overhead for single-thread programs. dnl --enable-libstdcxx-time=no dnl --disable-libstdcxx-time @@ -1175,8 +1177,7 @@ dnl os_defines.h and also defines _GLIBCXX_USE_SCHED_YIELD. dnl AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ - AC_MSG_CHECKING([for clock_gettime, nanosleep and sched_yield]) - GLIBCXX_ENABLE(libstdcxx-time,$1,[[[=KIND]]], + GLIBCXX_ENABLE(libstdcxx-time,auto,[[[=KIND]]], [use KIND for check type], [permit yes|no|rt]) @@ -1188,9 +1189,59 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ ac_has_clock_monotonic=no ac_has_clock_realtime=no - AC_MSG_RESULT($enable_libstdcxx_time) + ac_has_nanosleep=no + ac_has_sched_yield=no + + if test x"$enable_libstdcxx_time" = x"auto"; then + + case "${target_os}" in + cygwin*) + ac_has_nanosleep=yes + ;; + darwin*) + ac_has_nanosleep=yes + ac_has_sched_yield=yes + ;; + gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu) + AC_MSG_CHECKING([for at least GNU libc 2.17]) + AC_TRY_COMPILE( + [#include ], + [ + #if ! __GLIBC_PREREQ(2, 17) + #error + #endif + ], + [glibcxx_glibc217=yes], [glibcxx_glibc217=no]) + AC_MSG_RESULT($glibcxx_glibc217) + + if test x"$glibcxx_glibc217" = x"yes"; then + ac_has_clock_monotonic=yes + ac_has_clock_realtime=yes + fi + ac_has_nanosleep=yes + ac_has_sched_yield=yes + ;; + freebsd*|netbsd*) + ac_has_clock_monotonic=yes + ac_has_clock_realtime=yes + ac_has_nanosleep=yes + ac_has_sched_yield=yes + ;; + openbsd*) + ac_has_clock_monotonic=yes + ac_has_clock_realtime=yes + ac_has_nanosleep=yes + ;; + solaris*) + GLIBCXX_LIBS="$GLIBCXX_LIBS -lrt" + ac_has_clock_monotonic=yes + ac_has_clock_realtime=yes + ac_has_nanosleep=yes + ac_has_sched_yield=yes + ;; + esac - if test x"$enable_libstdcxx_time" != x"no"; then + elif test x"$enable_libstdcxx_time" != x"no"; then if test x"$enable_libstdcxx_time" = x"rt"; then AC_SEARCH_LIBS(clock_gettime, [rt posix4]) @@ -1214,19 +1265,16 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ case "$ac_cv_search_sched_yield" in -lposix4*) GLIBCXX_LIBS="$GLIBCXX_LIBS $ac_cv_search_sched_yield" - AC_DEFINE(_GLIBCXX_USE_SCHED_YIELD, 1, - [ Defined if sched_yield is available. ]) + ac_has_sched_yield=yes ;; -lrt*) if test x"$enable_libstdcxx_time" = x"rt"; then GLIBCXX_LIBS="$GLIBCXX_LIBS $ac_cv_search_sched_yield" - AC_DEFINE(_GLIBCXX_USE_SCHED_YIELD, 1, - [ Defined if sched_yield is available. ]) + ac_has_sched_yield=yes fi ;; *) - AC_DEFINE(_GLIBCXX_USE_SCHED_YIELD, 1, - [ Defined if sched_yield is available. ]) + ac_has_sched_yield=yes ;; esac @@ -1284,6 +1332,11 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ [ Defined if clock_gettime has realtime clock support. ]) fi + if test x"$ac_has_sched_yield" = x"yes"; then + AC_DEFINE(_GLIBCXX_USE_SCHED_YIELD, 1, + [ Defined if sched_yield is available. ]) + fi + if test x"$ac_has_nanosleep" = x"yes"; then AC_DEFINE(_GLIBCXX_USE_NANOSLEEP, 1, [ Defined if nanosleep is available. ]) diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 73d430a..f6ba176 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -198,8 +198,7 @@ GLIBCXX_COMPUTE_STDIO_INTEGER_CONSTANTS GLIBCXX_CHECK_GETTIMEOFDAY # For clock_gettime, nanosleep and sched_yield support. -# NB: The default is [no], because otherwise it requires linking. -GLIBCXX_ENABLE_LIBSTDCXX_TIME([no]) +GLIBCXX_ENABLE_LIBSTDCXX_TIME AC_LC_MESSAGES