From patchwork Fri Jan 10 21:23:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 104540 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 394133857833 for ; Fri, 10 Jan 2025 21:42:40 +0000 (GMT) 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 ESMTP id A59023857C7B for ; Fri, 10 Jan 2025 21:28:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A59023857C7B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A59023857C7B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736544511; cv=none; b=ngNf8Ocm4BRSJjK2m9z4thppJYAncuIkdqtLO16CO3XEYW8542hh00wl9k0ZuI/sEATatHcJZ6qQmTFydf9MuOsFdq5nxpVKwViaaHokNkVKp3SeK9bHkyPUnzEAevsnOhSKhCA/dsWMuwY2Ntvms9RfaWVjsY57h/FoBgpBJbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736544511; c=relaxed/simple; bh=Cb7cG0TqDDRtFUFHZsQFsj4Nj3bKyl/6o8sat3EZhH0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mOGo1A1nOVjRZkV5PE4a7Wd+N7FhoJbsS2JMFyzl383xA9QJZ70ZnE4AsmhC7VCZEEZZMvuPUAaMk+q7/SJpNjo/1GJL7kK+4SY2zzFPAutwpudZmiA1bpBJvUrrQw+Tr/8N68wEzU8m1vqNZiud1Q/u7TKJOZJ2qzCktoN9DX8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A59023857C7B Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XALLzTj1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736544511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3cmjYn62FkLNBlU80CXyBHsFHm4QR+Yo/IDVwRamRuQ=; b=XALLzTj1o58cTnl32OWK8S52KeygtfebnCtfFv3W0K6SoLveQwiLUZpXSxx+FLn3SUdAsl UR6+5C3ov6oUaIy+N7uxU8qAHw77QHwXmBdRJUm6pNVbWObDRn/a16GFkG5DaTvBbmas80 NwVLjL65DLq7v9j+0TZdMc2pZrPTHZQ= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-407-LywjJI7xOZeMPT4z1f7vxA-1; Fri, 10 Jan 2025 16:28:28 -0500 X-MC-Unique: LywjJI7xOZeMPT4z1f7vxA-1 X-Mimecast-MFC-AGG-ID: LywjJI7xOZeMPT4z1f7vxA Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5C8D119560B3; Fri, 10 Jan 2025 21:28:27 +0000 (UTC) Received: from localhost (unknown [10.42.28.9]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B6F8119560AD; Fri, 10 Jan 2025 21:28:26 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 06/10] libstdc++: Simplify futex wrapper functions for atomic wait/notify Date: Fri, 10 Jan 2025 21:23:09 +0000 Message-ID: <20250110212810.832494-7-jwakely@redhat.com> In-Reply-To: <20250110212810.832494-1-jwakely@redhat.com> References: <20250110212810.832494-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ndr6Tm3tzJpJYtkx8zJQmEKE4as4WH7UEU0qlozJhdc_1736544507 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 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_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Making these non-templates will allow them to be moved into the library at some point. libstdc++-v3/ChangeLog: * include/bits/atomic_wait.h (__platform_wait): Change function template to a normal function. The parameter is always __platform_wait_t* which is just int* for this implementation of the function. (__platform_notify): Likewise. --- libstdc++-v3/include/bits/atomic_wait.h | 40 ++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h index 4a9652ed8f1d..38a2bd3f95f2 100644 --- a/libstdc++-v3/include/bits/atomic_wait.h +++ b/libstdc++-v3/include/bits/atomic_wait.h @@ -108,27 +108,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __bitset_match_any = -1 }; - template - void - __platform_wait(const _Tp* __addr, __platform_wait_t __val) noexcept - { - auto __e = syscall (SYS_futex, static_cast(__addr), - static_cast(__futex_wait_flags::__wait_private), - __val, nullptr); - if (!__e || errno == EAGAIN) - return; - if (errno != EINTR) - __throw_system_error(errno); - } + // If the futex *__addr is equal to __val, wait on the futex until woken. + inline void + __platform_wait(const int* __addr, int __val) noexcept + { + auto __e = syscall (SYS_futex, __addr, + static_cast(__futex_wait_flags::__wait_private), + __val, nullptr); + if (!__e || errno == EAGAIN) + return; + if (errno != EINTR) + __throw_system_error(errno); + } - template - void - __platform_notify(const _Tp* __addr, bool __all) noexcept - { - syscall (SYS_futex, static_cast(__addr), - static_cast(__futex_wait_flags::__wake_private), - __all ? INT_MAX : 1); - } + // Wake threads waiting on the futex *__addr. + inline void + __platform_notify(const int* __addr, bool __all) noexcept + { + syscall (SYS_futex, __addr, + static_cast(__futex_wait_flags::__wake_private), + __all ? INT_MAX : 1); + } #endif inline void