From patchwork Fri Dec 10 14:08:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 48783 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F9E3385803F for ; Fri, 10 Dec 2021 14:09:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F9E3385803F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1639145399; bh=/DrYM+iC/Ntn0HfiyRrG7TazxC8B5giB7w6ww/zT+Ag=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=M5eRVm1x1IiVDegQEKNnxiLmJtZYp4BDTWTmiLFf4KPBLnXumWi4AUFkSw0YUsiRg QZWD+6YAF/mz+DDIHguq4bFDmm0cth32vWsLGkC3ImKq2IAzC8ElPy919N5otnU8yE 0BLfdWB1ymhHZ0j9Obfqy+M3jD5QE9k/M7p+lPTo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DD77E3857C69 for ; Fri, 10 Dec 2021 14:09:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DD77E3857C69 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-461-ZZWY3FTCONiVPeeRxGlfIw-1; Fri, 10 Dec 2021 09:08:57 -0500 X-MC-Unique: ZZWY3FTCONiVPeeRxGlfIw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79A6A100CCC2; Fri, 10 Dec 2021 14:08:56 +0000 (UTC) Received: from localhost (unknown [10.33.36.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2827C68D94; Fri, 10 Dec 2021 14:08:56 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Guard mutex and condvar with gthreads macro [PR103638] Date: Fri, 10 Dec 2021 14:08:55 +0000 Message-Id: <20211210140855.1654052-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested powerpc64le-linux --enable-threads={posix,single}, pushed to trunk. The testsuite is now clean for --enable-threads=single (apart from the expected abi-check failures, because the baselines are for the posix thread model). A mutex and condition variable is used for timed waits on atomics if there is no "platform wait" (e.g. futex) supported. But the use of those types wasn't guarded by the _GLIBCXX_HAS_GTHREADS macro, causing errors for --disable-threads builds. This fix allows to work on targets with futexes but no gthreads. libstdc++-v3/ChangeLog: PR libstdc++/103638 * include/bits/atomic_timed_wait.h: Check _GLIBCXX_HAS_GTHREADS before using std::mutex and std::__condvar. --- libstdc++-v3/include/bits/atomic_timed_wait.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libstdc++-v3/include/bits/atomic_timed_wait.h b/libstdc++-v3/include/bits/atomic_timed_wait.h index efbe3da8b6c..ba83398285c 100644 --- a/libstdc++-v3/include/bits/atomic_timed_wait.h +++ b/libstdc++-v3/include/bits/atomic_timed_wait.h @@ -137,6 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // (e.g. __ulock_wait())which is better than pthread_cond_clockwait #endif // ! PLATFORM_TIMED_WAIT +#ifdef _GLIBCXX_HAS_GTHREADS // Returns true if wait ended before timeout. // _Clock must be either steady_clock or system_clock. template @@ -192,6 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return false; } } +#endif // _GLIBCXX_HAS_GTHREADS struct __timed_waiter_pool : __waiter_pool_base { @@ -239,6 +241,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (_M_deadline <= __now) return false; + // FIXME: this_thread::sleep_for not available #ifdef _GLIBCXX_NO_SLEEP + auto __elapsed = __now - _M_t0; if (__elapsed > 128ms) {