This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Guard C++20 atomic type aliases
AbandonedPublic

Authored by miyuki on Feb 26 2020, 8:00 AM.

Details

Reviewers
ldionne
__simt__
EricWF
jfb
mclow.lists
Group Reviewers
Restricted Project
Summary

The std::atomic_signed_lock_free and std::atomic_unsigned_lock_free
typedefs are a C++20 feature and should be guarded with an #if, so
that they don't get defined in C++17 and prior versions.

Also with the current implementation inclusion of the <atomic> header
will fail the compilation for targets that don't have lock-free atomic
integers (e.g. Armv6-M) because libcpp_signed_lock_free and
libcpp_unsigned_lock_free will not get defined. We should not try to
define std::atomic_signed_lock_free and std::atomic_unsigned_lock_free
in this case as well (according to [atomics.alias]/2 these typedefs
are optional in freestanding implementations).

Diff Detail

Event Timeline

miyuki created this revision.Feb 26 2020, 8:00 AM
jfb added a comment.Feb 26 2020, 10:08 AM

Please add extensive tests, this will absolutely break in the future without them.

libcxx/include/atomic
2756

This should check that the configuration is indeed freestanding, and bail out if it's hosted.

jfb added a comment.Feb 26 2020, 10:24 AM

Actually: how are your locks implemented to support atomic? You disable interrupts? I think you want to contribute a version of atomic which does this, instead of saying "nothing is lock free, use locks" and then doing all the magic in the locks.

In D75183#1893997, @jfb wrote:

Actually: how are your locks implemented to support atomic? You disable interrupts? I think you want to contribute a version of atomic which does this, instead of saying "nothing is lock free, use locks" and then doing all the magic in the locks.

For operations used in libc++abi (atomic exchange, atomic compare-exchange) we provide weak definitions of atomic functions which work correctly in single-threaded environments. The idea is that the user will provide multithreaded versions, which would typically rely on RTOS API to disable/enable interrupts. Unfortunately the implementation is not complete.

I think I am going to abandon the patch for now.

miyuki abandoned this revision.Feb 27 2020, 2:58 AM
dim added a subscriber: dim.Dec 13 2021, 10:07 AM

It's a pity this never landed. Now libc++ can't work on older arm without non-standard patches... :)

Herald added a reviewer: Restricted Project. · View Herald TranscriptDec 13 2021, 10:07 AM