From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0B3E73858414; Mon, 28 Nov 2022 16:29:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B3E73858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669652998; bh=X/B4nnMiS7XkN38OkflmVEX9qqNR0LpvzAVxK25Pkx8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BFbApJId755dLC7rnsmGMtyL+2MLlHnx2EcNcE6qWEnz88YGSiA4e7K7EUqiJHes8 nHqIVxB5wcntadlRWAKEOjH7kdKWxtIYqJgoO9XB8Vquz+2tsrZhN6UbkPZDSTh1lO JqH2HySMGuNAEpmz4DoZI4VxURrv3NDpwiO83Gs8= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107886] Problem witch std::latch, std::binary_semaphores in C++20 Date: Mon, 28 Nov 2022 16:29:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.3.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107886 --- Comment #16 from Jonathan Wakely --- Something like ... --- include/bits/atomic_wait.h 2022-11-07 15:38:32.551751184 +0000 +++ /tmp/inc/bits/atomic_wait.h 2022-11-28 16:27:51.352489618 +0000 @@ -33,7 +33,7 @@ #pragma GCC system_header #include -#if defined _GLIBCXX_HAS_GTHREADS || defined _GLIBCXX_HAVE_LINUX_FUTEX +#if defined _GLIBCXX_HAS_GTHREADS || defined _GLIBCXX_HAVE_LINUX_FUTEX || _WIN32 #include #include #include @@ -59,6 +59,10 @@ #define _GLIBCXX_HAVE_PLATFORM_WAIT 1 using __platform_wait_t =3D int; inline constexpr size_t __platform_wait_alignment =3D 4; +#elif _WIN32 + using __platform_wait_t =3D __UINTPTR_TYPE__; + inline constexpr size_t __platform_wait_alignment + =3D alignof(__platform_wait_t); #else // define _GLIBCX_HAVE_PLATFORM_WAIT and implement __platform_wait() // and __platform_notify() if there is a more efficient primitive supported @@ -122,6 +126,30 @@ static_cast(__futex_wait_flags::__wake_private), __all ? INT_MAX : 1); } +#elif _WIN32 + extern "C" int __glibcxx_get_last_error() __asm("GetLastError"); + + template + void + __platform_wait(const _Tp* __addr, __platform_wait_t __val) noexcept + { + const long __timeout =3D 0xffffffff; + if (WaitOnAddress(__addr, &__val, sizeof(__platform_wait_t), __timeout)) + return; + _GLIBCXX_THROW_OR_ABORT(std::system_error(__glibcxx_get_last_error= (), + std::system_category(), + "WaitOnAddress")); + } + + template + void + __platform_notify(const _Tp* __addr, bool __all) noexcept + { + if (__all) + WakeByAddressAll(__addr); + else + WakeByAddressOne(__addr); + } #endif inline void=