Skip to content

Commit

Permalink
[libc++] Handle _LIBCPP_HAS_NO_{THREADS,LOCALIZATION} consistently wi…
Browse files Browse the repository at this point in the history
…th other carve-outs

Previously, we would issue an #error when using a header that requires
threading support or localization support in a configuration where that
is disabled. This is unlike what we do for all the other carve outs
like no-filesystem, no-wide-characters or no-random-device. Instead of
issuing an #error, we normally just remove the problematic parts of the
header.

This patch makes the handling of no-localization and no-threads consistent
with the other carve-outs. I dislike the fact that users won't get an
explicit error message when trying to use e.g. ios in a build that doesn't
support localization, but I think it is better to handle things consistently.
Note that besides the consistency argument, the #error approach doesn't
really work anyways since it would break down if we moved towards assuming
the C locale only in the no-localization mode.
  • Loading branch information
ldionne committed Jul 10, 2024
1 parent af21bc1 commit e37a5c2
Show file tree
Hide file tree
Showing 10 changed files with 381 additions and 379 deletions.
52 changes: 26 additions & 26 deletions libcxx/include/barrier
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,36 @@ namespace std

#include <__config>

#ifdef _LIBCPP_HAS_NO_THREADS
# error "<barrier> is not supported since libc++ has been configured without support for threads."
#endif

#include <__assert>
#include <__atomic/atomic_base.h>
#include <__atomic/memory_order.h>
#include <__memory/unique_ptr.h>
#include <__thread/poll_with_backoff.h>
#include <__thread/timed_backoff_policy.h>
#include <__utility/move.h>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <version>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#if !defined(_LIBCPP_HAS_NO_THREADS)

# include <__assert>
# include <__atomic/atomic_base.h>
# include <__atomic/memory_order.h>
# include <__memory/unique_ptr.h>
# include <__thread/poll_with_backoff.h>
# include <__thread/timed_backoff_policy.h>
# include <__utility/move.h>
# include <cstddef>
# include <cstdint>
# include <limits>
# include <version>

# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif

_LIBCPP_PUSH_MACROS
#include <__undef_macros>
# include <__undef_macros>

#if _LIBCPP_STD_VER >= 14
# if _LIBCPP_STD_VER >= 14

_LIBCPP_BEGIN_NAMESPACE_STD

struct __empty_completion {
inline _LIBCPP_HIDE_FROM_ABI void operator()() noexcept {}
};

# ifndef _LIBCPP_HAS_NO_TREE_BARRIER
# ifndef _LIBCPP_HAS_NO_TREE_BARRIER

/*
Expand Down Expand Up @@ -152,7 +150,7 @@ public:
}
};

# else
# else

/*
Expand Down Expand Up @@ -253,7 +251,7 @@ public:
}
};

# endif // !_LIBCPP_HAS_NO_TREE_BARRIER
# endif // !_LIBCPP_HAS_NO_TREE_BARRIER

template <class _CompletionF = __empty_completion>
class _LIBCPP_DEPRECATED_ATOMIC_SYNC barrier {
Expand All @@ -265,7 +263,7 @@ public:
static _LIBCPP_HIDE_FROM_ABI constexpr ptrdiff_t max() noexcept { return __barrier_base<_CompletionF>::max(); }

_LIBCPP_AVAILABILITY_SYNC
_LIBCPP_HIDE_FROM_ABI explicit barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF())
_LIBCPP_HIDE_FROM_ABI explicit barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF())
: __b_(__count, std::move(__completion)) {
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
__count >= 0,
Expand All @@ -292,10 +290,12 @@ public:

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP_STD_VER >= 14
# endif // _LIBCPP_STD_VER >= 14

_LIBCPP_POP_MACROS

#endif // !defined(_LIBCPP_HAS_NO_THREADS)

#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
# include <atomic>
# include <concepts>
Expand Down
Loading

0 comments on commit e37a5c2

Please sign in to comment.