]> gcc.gnu.org Git - gcc.git/commit
libstdc++: Fix src/c++20/tzdb.cc for non-constexpr std::mutex
authorJonathan Wakely <jwakely@redhat.com>
Thu, 29 Jun 2023 10:40:32 +0000 (11:40 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 29 Jun 2023 15:17:23 +0000 (16:17 +0100)
commit5dfdf0ae4dca44a4f572c346d322fd6244598190
treeb808ea0b56d6bc520e53c7bcef06fe675d5c0912
parentff29ee6af88f709e08ee467869d8c1b13889a724
libstdc++: Fix src/c++20/tzdb.cc for non-constexpr std::mutex

Building libstdc++ reportedly fails for targets without lock-free
std::atomic<T*> which don't define __GTHREAD_MUTEX_INIT:

src/c++20/tzdb.cc:110:21: error: 'constinit' variable 'std::chrono::{anonymous}::list_mutex' does not have a constant initializer
src/c++20/tzdb.cc:110:21: error: call to non-'constexpr' function 'std::mutex::mutex()'

The solution implemented by this commit is to use a local static mutex
when it can't be constinit, so that it's constructed on first use.

With this change, we can also simplify the preprocessor logic for
defining USE_ATOMIC_SHARED_PTR. It now depends on the same conditions as
USE_ATOMIC_LIST_HEAD, so in theory we could have a single macro. Keeping
them separate would allow us to replace the use of atomic<shared_ptr<T>>
with a mutex if that performs better, without having to give up on the
lock-free cache for fast access to the list head.

libstdc++-v3/ChangeLog:

* src/c++20/tzdb.cc (USE_ATOMIC_SHARED_PTR): Define consistently
with USE_ATOMIC_LIST_HEAD.
(list_mutex): Replace global object with function. Use local
static object when std::mutex constructor isn't constexpr.
libstdc++-v3/src/c++20/tzdb.cc
This page took 0.066533 seconds and 6 git commands to generate.