]> 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>
Tue, 18 Jul 2023 09:05:48 +0000 (10:05 +0100)
commitc17539d71b287fd3b7cd781af1f1dffabef659ee
tree27f1ea9729040aef0209177434ce507ba79c0e7d
parentdae963588777df4317cdf81740a4b3de8debd78b
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.

(cherry picked from commit 5dfdf0ae4dca44a4f572c346d322fd6244598190)
libstdc++-v3/src/c++20/tzdb.cc
This page took 0.05495 seconds and 6 git commands to generate.