1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___THREAD_HARDWARE_CONCURRENCY_H
11#define _LIBCPP___THREAD_HARDWARE_CONCURRENCY_H
12
13#include <__config>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19_LIBCPP_PUSH_MACROS
20#include <__undef_macros>
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
24
25#if _LIBCPP_STD_VER >= 11 && _LIBCPP_HAS_THREADS
26
27// __thread_hardware_concurrency() has the same semantics as std::[j]thread::hardware_concurrency(), but allows querying
28// this information without depending on std::thread itself. This function is an alias to
29// std::thread::hardware_concurrency(), which is a part of the ABI.
30
31# ifdef _LIBCPP_ABI_MICROSOFT
32# define _LIBCPP_THREAD_HARDWARE_CONCURRENCY_SYMBOL \
33 "?hardware_concurrency@thread@" _LIBCPP_TOSTRING(_LIBCPP_ABI_NAMESPACE) "@std@@SAIXZ"
34# else
35# define _LIBCPP_THREAD_HARDWARE_CONCURRENCY_SYMBOL \
36 _LIBCPP_TOSTRING(__USER_LABEL_PREFIX__) \
37 "_ZNSt" _LIBCPP_TOSTRING(_LIBCPP_ABI_NAMESPACE_LEN) \
38 _LIBCPP_TOSTRING(_LIBCPP_ABI_NAMESPACE) "6thread20hardware_concurrencyEv"
39# endif
40
41[[__nodiscard__]] _LIBCPP_EXPORTED_FROM_ABI unsigned __thread_hardware_concurrency() _NOEXCEPT
42 __asm__(_LIBCPP_THREAD_HARDWARE_CONCURRENCY_SYMBOL);
43
44#endif // _LIBCPP_STD_VER >= 11 && _LIBCPP_HAS_THREADS
45
46_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
47_LIBCPP_END_NAMESPACE_STD
48
49_LIBCPP_POP_MACROS
50
51#endif // _LIBCPP___THREAD_HARDWARE_CONCURRENCY_H
52