Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:43

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___THREAD_FORMATTER_H
0011 #define _LIBCPP___CXX03___THREAD_FORMATTER_H
0012 
0013 #include <__cxx03/__concepts/arithmetic.h>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__format/concepts.h>
0016 #include <__cxx03/__format/format_parse_context.h>
0017 #include <__cxx03/__format/formatter.h>
0018 #include <__cxx03/__format/formatter_integral.h>
0019 #include <__cxx03/__format/parser_std_format_spec.h>
0020 #include <__cxx03/__thread/id.h>
0021 #include <__cxx03/__type_traits/conditional.h>
0022 #include <__cxx03/__type_traits/is_pointer.h>
0023 #include <__cxx03/__type_traits/is_same.h>
0024 #include <__cxx03/cstdint>
0025 
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 #  pragma GCC system_header
0028 #endif
0029 
0030 #if _LIBCPP_STD_VER >= 23
0031 
0032 _LIBCPP_BEGIN_NAMESPACE_STD
0033 
0034 #  ifndef _LIBCPP_HAS_NO_THREADS
0035 
0036 template <__fmt_char_type _CharT>
0037 struct _LIBCPP_TEMPLATE_VIS formatter<__thread_id, _CharT> {
0038 public:
0039   template <class _ParseContext>
0040   _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
0041     return __parser_.__parse(__ctx, __format_spec::__fields_fill_align_width);
0042   }
0043 
0044   template <class _FormatContext>
0045   _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(__thread_id __id, _FormatContext& __ctx) const {
0046     // In __thread/support/pthread.h, __libcpp_thread_id is either a
0047     // unsigned long long or a pthread_t.
0048     //
0049     // The type of pthread_t is left unspecified in POSIX so it can be any
0050     // type. The most logical types are an integral or pointer.
0051     // On Linux systems pthread_t is an unsigned long long.
0052     // On Apple systems pthread_t is a pointer type.
0053     //
0054     // Note the output should match what the stream operator does. Since
0055     // the ostream operator has been shipped years before this formatter
0056     // was added to the Standard, this formatter does what the stream
0057     // operator does. This may require platform specific changes.
0058 
0059     using _Tp = decltype(__get_underlying_id(__id));
0060     using _Cp = conditional_t<integral<_Tp>, _Tp, conditional_t<is_pointer_v<_Tp>, uintptr_t, void>>;
0061     static_assert(!is_same_v<_Cp, void>, "unsupported thread::id type, please file a bug report");
0062 
0063     __format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx);
0064     if constexpr (is_pointer_v<_Tp>) {
0065       __specs.__std_.__alternate_form_ = true;
0066       __specs.__std_.__type_           = __format_spec::__type::__hexadecimal_lower_case;
0067     }
0068     return __formatter::__format_integer(reinterpret_cast<_Cp>(__get_underlying_id(__id)), __ctx, __specs);
0069   }
0070 
0071   __format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__right};
0072 };
0073 
0074 #  endif // !_LIBCPP_HAS_NO_THREADS
0075 
0076 _LIBCPP_END_NAMESPACE_STD
0077 
0078 #endif // _LIBCPP_STD_VER >= 23
0079 
0080 #endif // _LIBCPP___CXX03___THREAD_FORMATTER_H