From patchwork Wed Oct 31 00:57:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 195670 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]) by ozlabs.org (Postfix) with SMTP id 807ED2C0095 for ; Wed, 31 Oct 2012 11:58:31 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1352249912; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=p2CLJkDdsAHP+vftmdvmXJaifTM=; b=ktI0pOniPJ9PrC+ucko2E8N6GZIUykiSzS9d5stij4zpzRvC1xe4aN2/oC5qM2 5tvlCq3r/iDv+hc/2FxXtNUZ8njDDijweCKJ/10vYsFhEIAk9NsNymUtToBUYzJl zzqyYRhPzE09TjhpsRcUXKZe5rn8zqCW7hokEYh8OX5X0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:In-Reply-To:References:Date:Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=s4SfcMxo75qg9J7k5Gr5UDGmGPoAOq85Wz87K8p9Mx6fW3T0HW4Hk0q9D7ueRH 8tK/2hgbGThZGi6VPheQHJYdOQEDpUZ1ha+Km8P4bgomzGLeKBDeIsoNbPKM7uq0 t2CkudQBBd04DAthXRMNzQjgW4gh3VvdVsxxEK/id/N94=; Received: (qmail 12884 invoked by alias); 31 Oct 2012 00:58:18 -0000 Received: (qmail 12866 invoked by uid 22791); 31 Oct 2012 00:58:17 -0000 X-SWARE-Spam-Status: No, hits=-5.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_CX, TW_DC, TW_FN, TW_XX X-Spam-Check-By: sourceware.org Received: from mail-ia0-f175.google.com (HELO mail-ia0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 31 Oct 2012 00:57:22 +0000 Received: by mail-ia0-f175.google.com with SMTP id b35so714550iac.20 for ; Tue, 30 Oct 2012 17:57:21 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.194.132 with SMTP id hw4mr3222003igc.35.1351645041444; Tue, 30 Oct 2012 17:57:21 -0700 (PDT) Received: by 10.42.158.202 with HTTP; Tue, 30 Oct 2012 17:57:21 -0700 (PDT) In-Reply-To: References: Date: Wed, 31 Oct 2012 00:57:21 +0000 Message-ID: Subject: Re: Is libstdcxx-time still experimental? From: Jonathan Wakely To: "libstdc++" Cc: GCC Patches 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 On 26 August 2012 18:20, Jonathan Wakely wrote: >> I'm working on a patch to enable it by default and to define >> this_thread::sleep_xxx and this_thread::yield unconditionally. > > For anyone interested, here's a work-in-progress patch that enables > this_thread::sleep_for() and this_thread::yield() unconditionally, so > those APIs are complete even if --enable-libstdcxx-time isn't used. I'm planning to commit something very similar to this before the end of stage 1, but with __sleep_for always exported from libstdc++.so to avoid --enable-libstdcxx-time changing the library API. commit 5fb51138670365f69942c42da7b0ec24a1e752d2 Author: Jonathan Wakely Date: Thu Aug 9 20:16:13 2012 +0100 * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Check for usleep and sleep if nanosleep is not available. Bump libtool revision. * config.h.in: Regenerate. * configure: Likewise. * config/abi/pre/gnu.ver (GLIBCXX_3.4.18): Add __sleep_for. * include/std/thread (this_thread::__sleep_for): Add. (this_thread::yield,this_thread::sleep_until, this_thread::sleep_for): Declare unconditionally. * src/c++11/thread.cc (this_thread::__sleep_for): Define. * testsuite/lib/libstdc++.exp (check_v3_target_nanosleep): Rename to check_v3_target_sleep. * testsuite/lib/dg-options.exp (dg-require-nanosleep): Rename to dg-require-sleep. * testsuite/30_threads/condition_variable_any/53830.cc: Update. * testsuite/30_threads/this_thread/2.cc: Likewise. * testsuite/30_threads/this_thread/3.cc: Likewise. * testsuite/30_threads/this_thread/4.cc: Likewise. diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 1179407..b9f8ed5 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -1246,6 +1246,20 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ if test x"$ac_has_nanosleep" = x"yes"; then AC_DEFINE(_GLIBCXX_USE_NANOSLEEP, 1, [ Defined if nanosleep is available. ]) + else + AC_MSG_CHECKING([for sleep]) + AC_TRY_COMPILE([#include ], + [sleep(1)], + [AC_DEFINE(HAVE_SLEEP,1, + [Defined if sleep exists.])],[]) + AC_MSG_RESULT($ac_has_sleep) + AC_MSG_CHECKING([for usleep]) + AC_TRY_COMPILE([#include ], + [sleep(1); + usleep(100);], + [AC_DEFINE(HAVE_USLEEP,1, + [Defined if usleep exists.])],[]) + AC_MSG_RESULT($ac_has_usleep) fi AC_SUBST(GLIBCXX_LIBS) @@ -3139,7 +3153,7 @@ changequote([,])dnl fi # For libtool versioning info, format is CURRENT:REVISION:AGE -libtool_VERSION=6:17:0 +libtool_VERSION=6:18:0 # Everything parsed; figure out what files and settings to use. case $enable_symvers in diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index cd0be4e..13e4cf8 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -1321,6 +1321,13 @@ GLIBCXX_3.4.17 { } GLIBCXX_3.4.16; +GLIBCXX_3.4.18 { + + # std::this_thread::__sleep_for + _ZNSt11this_thread11__sleep_for*; + +} GLIBCXX_3.4.17; + # Symbols in the support library (libsupc++) have their own tag. CXXABI_1.3 { diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread index 8a45b65..6f1e3fc 100644 --- a/libstdc++-v3/include/std/thread +++ b/libstdc++-v3/include/std/thread @@ -249,32 +249,39 @@ _GLIBCXX_END_NAMESPACE_VERSION inline thread::id get_id() noexcept { return thread::id(__gthread_self()); } -#ifdef _GLIBCXX_USE_SCHED_YIELD /// yield inline void yield() noexcept - { __gthread_yield(); } + { +#ifdef _GLIBCXX_USE_SCHED_YIELD + __gthread_yield(); #endif + } + + void + __sleep_for(chrono::seconds, chrono::nanoseconds); #ifdef _GLIBCXX_USE_NANOSLEEP + inline void + __sleep_for(chrono::seconds __s, chrono::nanoseconds __ns) + { + __gthread_time_t __ts = + { + static_cast(__s.count()), + static_cast(__ns.count()) + }; + ::nanosleep(&__ts, 0); + } +#endif + /// sleep_for template inline void sleep_for(const chrono::duration<_Rep, _Period>& __rtime) { - chrono::seconds __s = - chrono::duration_cast(__rtime); - - chrono::nanoseconds __ns = - chrono::duration_cast(__rtime - __s); - - __gthread_time_t __ts = - { - static_cast(__s.count()), - static_cast(__ns.count()) - }; - - ::nanosleep(&__ts, 0); + auto __s = chrono::duration_cast(__rtime); + auto __ns = chrono::duration_cast(__rtime - __s); + __sleep_for(__s, __ns); } /// sleep_until @@ -282,7 +289,6 @@ _GLIBCXX_END_NAMESPACE_VERSION inline void sleep_until(const chrono::time_point<_Clock, _Duration>& __atime) { sleep_for(__atime - _Clock::now()); } -#endif _GLIBCXX_END_NAMESPACE_VERSION } diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc index 5c10832..90bd835 100644 --- a/libstdc++-v3/src/c++11/thread.cc +++ b/libstdc++-v3/src/c++11/thread.cc @@ -1,6 +1,6 @@ // thread -*- C++ -*- -// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc. +// Copyright (C) 2008-2012 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -27,6 +27,8 @@ #include #include +#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) + #if defined(_GLIBCXX_USE_GET_NPROCS) # include # define _GLIBCXX_NPROCS get_nprocs() @@ -55,7 +57,13 @@ static inline int get_nprocs() # define _GLIBCXX_NPROCS 0 #endif -#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) +#ifndef _GLIBCXX_USE_NANOSLEEP +# ifdef _GLIBCXX_USE_SLEEP +# include +# else +# error "No sleep function known for this target" +# endif +#endif namespace std _GLIBCXX_VISIBILITY(default) { @@ -142,6 +150,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } _GLIBCXX_END_NAMESPACE_VERSION + +namespace this_thread +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +#ifndef _GLIBCXX_USE_NANOSLEEP + void + __sleep_for(chrono::seconds __s, chrono::nanoseconds __ns) + { +#ifdef _GLIBCXX_USE_SLEEP +#ifdef _GLIBCXX_USE_USLEEP + ::sleep(__s.count()); + if (__ns.count() > 0) + { + long __us = __ns.count() / 1000; + if (__us == 0) + __us = 1; + ::usleep(__us); + } +#else + ::sleep(__s.count() + (__ns >= 1000000)); +#endif +#endif + } +#endif + +_GLIBCXX_END_NAMESPACE_VERSION +} + } // namespace std #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable_any/53830.cc b/libstdc++-v3/testsuite/30_threads/condition_variable_any/53830.cc index 91aa348..a5279f6 100644 --- a/libstdc++-v3/testsuite/30_threads/condition_variable_any/53830.cc +++ b/libstdc++-v3/testsuite/30_threads/condition_variable_any/53830.cc @@ -5,7 +5,7 @@ // { dg-require-cstdint "" } // { dg-require-gthreads "" } // { dg-require-sched-yield "" } -// { dg-require-nanosleep "" } +// { dg-require-sleep "" } // Copyright (C) 2012 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/30_threads/this_thread/2.cc b/libstdc++-v3/testsuite/30_threads/this_thread/2.cc index f6b4740..6f5dd0f 100644 --- a/libstdc++-v3/testsuite/30_threads/this_thread/2.cc +++ b/libstdc++-v3/testsuite/30_threads/this_thread/2.cc @@ -4,9 +4,8 @@ // { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } // { dg-require-cstdint "" } // { dg-require-gthreads "" } -// { dg-require-sched-yield "" } -// Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. +// Copyright (C) 2008-2012 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the diff --git a/libstdc++-v3/testsuite/30_threads/this_thread/3.cc b/libstdc++-v3/testsuite/30_threads/this_thread/3.cc index b765f86..35f65f4 100644 --- a/libstdc++-v3/testsuite/30_threads/this_thread/3.cc +++ b/libstdc++-v3/testsuite/30_threads/this_thread/3.cc @@ -4,9 +4,9 @@ // { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } // { dg-require-cstdint "" } // { dg-require-gthreads "" } -// { dg-require-nanosleep "" } +// { dg-require-sleep "" } -// Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. +// Copyright (C) 2008-2012 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the diff --git a/libstdc++-v3/testsuite/30_threads/this_thread/4.cc b/libstdc++-v3/testsuite/30_threads/this_thread/4.cc index 2f8e27a..38a2a3c 100644 --- a/libstdc++-v3/testsuite/30_threads/this_thread/4.cc +++ b/libstdc++-v3/testsuite/30_threads/this_thread/4.cc @@ -4,9 +4,9 @@ // { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } // { dg-require-cstdint "" } // { dg-require-gthreads "" } -// { dg-require-nanosleep "" } +// { dg-require-sleep "" } -// Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. +// Copyright (C) 2008-2012 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp index 9d5624a..8a8a13f 100644 --- a/libstdc++-v3/testsuite/lib/dg-options.exp +++ b/libstdc++-v3/testsuite/lib/dg-options.exp @@ -143,8 +143,8 @@ proc dg-require-gthreads-timed { args } { return } -proc dg-require-nanosleep { args } { - if { ![ check_v3_target_nanosleep ] } { +proc dg-require-sleep { args } { + if { ![ check_v3_target_sleep ] } { upvar dg-do-what dg-do-what set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] return diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index 9a9e0cb..4ad6868 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -1352,41 +1352,43 @@ proc check_v3_target_gthreads_timed { } { } -proc check_v3_target_nanosleep { } { +proc check_v3_target_sleep { } { global cxxflags global DEFAULT_CXXFLAGS - global et_nanosleep + global et_sleep global tool - if { ![info exists et_nanosleep_target_name] } { - set et_nanosleep_target_name "" + if { ![info exists et_sleep_target_name] } { + set et_sleep_target_name "" } # If the target has changed since we set the cached value, clear it. set current_target [current_target_name] - if { $current_target != $et_nanosleep_target_name } { - verbose "check_v3_target_nanosleep: `$et_nanosleep_target_name'" 2 - set et_nanosleep_target_name $current_target - if [info exists et_nanosleep] { - verbose "check_v3_target_nanosleep: removing cached result" 2 - unset et_nanosleep + if { $current_target != $et_sleep_target_name } { + verbose "check_v3_target_sleep: `$et_sleep_target_name'" 2 + set et_sleep_target_name $current_target + if [info exists et_sleep] { + verbose "check_v3_target_sleep: removing cached result" 2 + unset et_sleep } } - if [info exists et_nanosleep] { - verbose "check_v3_target_nanosleep: using cached result" 2 + if [info exists et_sleep] { + verbose "check_v3_target_sleep: using cached result" 2 } else { - set et_nanosleep 0 + set et_sleep 0 - # Set up and preprocess a C++0x test program that depends - # on the nanosleep facilities to be available. - set src nanosleep[pid].cc + # Set up and preprocess a C++11 test program that depends + # on the sleep facilities to be available. + set src sleep[pid].cc set f [open $src "w"] puts $f "#include " puts $f "#ifndef _GLIBCXX_USE_NANOSLEEP" - puts $f "# error No nanosleep" + puts $f "# ifndef _GLIBCXX_HAVE_SLEEP" + puts $f "# error No nanosleep or sleep" + puts $f "# endif" puts $f "#endif" close $f @@ -1399,13 +1401,13 @@ proc check_v3_target_nanosleep { } { if [string match "" $lines] { # No error message, preprocessing succeeded. - set et_nanosleep 1 + set et_sleep 1 } else { - verbose "check_v3_target_nanosleep: compilation failed" 2 + verbose "check_v3_target_sleep: compilation failed" 2 } } - verbose "check_v3_target_nanosleep: $et_nanosleep" 2 - return $et_nanosleep + verbose "check_v3_target_sleep: $et_sleep" 2 + return $et_sleep } proc check_v3_target_sched_yield { } {