Files
clang-p2996/libcxx/include/__thread/formatter.h
Ian Anderson 571178a21a [libc++][Modules] Make top level modules for all C++ headers with OS/clang versions
The headers that include_next compiler and OS headers need to be in different top level modules in order to avoid module cycles. e.g. libc++'s stdlib.h will #include_next stdlib.h from the compiler and then the C library. Either of those are likely to include stddef.h, which will come back up to the libc++ module map and create a module cycle. Putting stdlib.h and stddef.h (and the rest of the C standard library headers) in top level modules resolves this by letting the order go cxx_stdlib_h -> os_stdlib_h -> cxx_stddef_h -> os_stddef_h.

All of those headers' dependencies then need to be moved into top level modules themselves to avoid module cycles between the new top level level cstd modules. This starts to get complicated, as the libc++ C headers, by standard, have to include many of the C++ headers, which include the private detail headers, which are intertwined. e.g. some `__algorithm` headers include `__memory` headers and vice versa.

Make top level modules for all of the libc++ headers to easily guarantee that the modules aren't cyclic.

Add enough module exports to fix `check-cxx` and `run-buildbot generic-modules`.

`__stop_token/intrusive_shared_ptr.h` uses `__atomic/atomic.h` but has no include path to it. Add that include.
`math.h` absorbs `bits/atomic_wide_counter.h` on some platforms that don't have modules, work around that by including `math.h` in `__threading_support`.
<mutex> doesn't actually require threads, there are a few pieces like once_flag that work without threads. Remove the requirement from its module.
AIX is no longer able to support modular builds.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D144322
2023-07-20 12:49:20 -07:00

81 lines
3.1 KiB
C++

// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___THREAD_FORMATTER_H
#define _LIBCPP___THREAD_FORMATTER_H
#include <__concepts/arithmetic.h>
#include <__config>
#include <__format/concepts.h>
#include <__format/format_parse_context.h>
#include <__format/formatter.h>
#include <__format/formatter_integral.h>
#include <__format/parser_std_format_spec.h>
#include <__thread/id.h>
#include <__type_traits/conditional.h>
#include <__type_traits/is_pointer.h>
#include <__type_traits/is_same.h>
#include <cstdint>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#if _LIBCPP_STD_VER >= 23
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_THREADS
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<__thread_id, _CharT> {
public:
template <class _ParseContext>
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
return __parser_.__parse(__ctx, __format_spec::__fields_fill_align_width);
}
template <class _FormatContext>
_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(__thread_id __id, _FormatContext& __ctx) const {
// In __threading_support __libcpp_thread_id is either a
// unsigned long long or a pthread_t.
//
// The type of pthread_t is left unspecified in POSIX so it can be any
// type. The most logical types are an integral or pointer.
// On Linux systems pthread_t is an unsigned long long.
// On Apple systems pthread_t is a pointer type.
//
// Note the output should match what the stream operator does. Since
// the ostream operator has been shipped years before this formatter
// was added to the Standard, this formatter does what the stream
// operator does. This may require platform specific changes.
using _Tp = decltype(__get_underlying_id(__id));
using _Cp = conditional_t<integral<_Tp>, _Tp, conditional_t<is_pointer_v<_Tp>, uintptr_t, void>>;
static_assert(!is_same_v<_Cp, void>, "unsupported thread::id type, please file a bug report");
__format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx);
if constexpr (is_pointer_v<_Tp>) {
__specs.__std_.__alternate_form_ = true;
__specs.__std_.__type_ = __format_spec::__type::__hexadecimal_lower_case;
}
return __formatter::__format_integer(reinterpret_cast<_Cp>(__get_underlying_id(__id)), __ctx, __specs);
}
__format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__right};
};
#endif // !_LIBCPP_HAS_NO_THREADS
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER >= 23
#endif // _LIBCPP___THREAD_FORMATTER_H