[Support] Avoid misguided FreeBSD hack (#177508)
FreeBSD doesn't do anything wrong here, it just happens to define and
use a struct thread in its own headers. The problems arise because here
in LLVM we have using namespace llvm prior to including system headers,
which is bad practice for precisely this reason. If we instead play by
the rules and defer our using namespace llvm until after we've included
the system headers then we no longer need this hack.
This hack is particularly problematic by being conditional on
__FreeBSD__ as of 9093ba9f7ee5 ("[Support] Include Support/thread.h
before api implementations (#111175)"), since on non-FreeBSD
Threading.inc can reference anything in Support/thread.h, only causing
errors on FreeBSD, which is precisely what happened in 64be34c562a2
("Enable using threads on z/OS (#171847)").
By deferring the using namespace llvm until after Threading.inc is
included there may be build failures introduced on untested platforms
due to needing to replace unqualified identifiers with qualified ones by
prepending llvm::.
This commit is contained in:
parent
f6f5ad3e0b
commit
f7361efc07
@ -20,8 +20,6 @@
|
||||
#include <optional>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//=== WARNING: Implementation here must contain only TRULY operating system
|
||||
//=== independent code.
|
||||
@ -29,6 +27,9 @@ using namespace llvm;
|
||||
|
||||
#if LLVM_ENABLE_THREADS == 0 || \
|
||||
(!defined(_WIN32) && !defined(HAVE_PTHREAD_H))
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
uint64_t llvm::get_threadid() { return 0; }
|
||||
|
||||
uint32_t llvm::get_max_thread_name_length() { return 0; }
|
||||
@ -51,6 +52,16 @@ int llvm::get_physical_cores() { return -1; }
|
||||
|
||||
static int computeHostNumHardwareThreads();
|
||||
|
||||
// Include the platform-specific parts of this class.
|
||||
#ifdef LLVM_ON_UNIX
|
||||
#include "Unix/Threading.inc"
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#include "Windows/Threading.inc"
|
||||
#endif
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
unsigned llvm::ThreadPoolStrategy::compute_thread_count() const {
|
||||
if (UseJobserver)
|
||||
if (auto JS = JobserverClient::getInstance())
|
||||
@ -67,19 +78,6 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const {
|
||||
return std::min((unsigned)MaxThreadCount, ThreadsRequested);
|
||||
}
|
||||
|
||||
// Include the platform-specific parts of this class.
|
||||
#ifdef LLVM_ON_UNIX
|
||||
#include "Unix/Threading.inc"
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#include "Windows/Threading.inc"
|
||||
#endif
|
||||
|
||||
// Must be included after Threading.inc to provide definition for llvm::thread
|
||||
// because FreeBSD's condvar.h (included by user.h) misuses the "thread"
|
||||
// keyword.
|
||||
#include "llvm/Support/thread.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// Darwin's default stack size for threads except the main one is only 512KB,
|
||||
// which is not enough for some/many normal LLVM compilations. This implements
|
||||
|
||||
@ -33,12 +33,7 @@
|
||||
#include <pthread_np.h> // For pthread_getthreadid_np() / pthread_set_name_np()
|
||||
#endif
|
||||
|
||||
// Must be included after Threading.inc to provide definition for llvm::thread
|
||||
// because FreeBSD's condvar.h (included by user.h) misuses the "thread"
|
||||
// keyword.
|
||||
#ifndef __FreeBSD__
|
||||
#include "llvm/Support/thread.h"
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
#include <errno.h>
|
||||
@ -278,7 +273,8 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
|
||||
#endif
|
||||
}
|
||||
|
||||
SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
|
||||
llvm::SetThreadPriorityResult
|
||||
llvm::set_thread_priority(ThreadPriority Priority) {
|
||||
#if (defined(__linux__) || defined(__CYGWIN__)) && defined(SCHED_IDLE)
|
||||
// Some *really* old glibcs are missing SCHED_IDLE.
|
||||
// http://man7.org/linux/man-pages/man3/pthread_setschedparam.3.html
|
||||
@ -376,15 +372,15 @@ static int computeHostNumPhysicalCores() {
|
||||
<< "/proc/cpuinfo: " << EC.message() << "\n";
|
||||
return -1;
|
||||
}
|
||||
SmallVector<StringRef, 8> strs;
|
||||
llvm::SmallVector<llvm::StringRef, 8> strs;
|
||||
(*Text)->getBuffer().split(strs, "\n", /*MaxSplit=*/-1,
|
||||
/*KeepEmpty=*/false);
|
||||
int CurProcessor = -1;
|
||||
int CurPhysicalId = -1;
|
||||
int CurSiblings = -1;
|
||||
int CurCoreId = -1;
|
||||
for (StringRef Line : strs) {
|
||||
std::pair<StringRef, StringRef> Data = Line.split(':');
|
||||
for (llvm::StringRef Line : strs) {
|
||||
std::pair<llvm::StringRef, llvm::StringRef> Data = Line.split(':');
|
||||
auto Name = Data.first.trim();
|
||||
auto Val = Data.second.trim();
|
||||
// These fields are available if the kernel is configured with CONFIG_SMP.
|
||||
|
||||
@ -105,7 +105,8 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
|
||||
Name.clear();
|
||||
}
|
||||
|
||||
SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
|
||||
llvm::SetThreadPriorityResult
|
||||
llvm::set_thread_priority(ThreadPriority Priority) {
|
||||
#ifdef THREAD_POWER_THROTTLING_CURRENT_VERSION
|
||||
HMODULE kernelM = llvm::sys::windows::loadSystemModuleSecure(L"kernel32.dll");
|
||||
if (kernelM) {
|
||||
@ -208,9 +209,9 @@ static std::optional<std::vector<USHORT>> getActiveGroups() {
|
||||
return Groups;
|
||||
}
|
||||
|
||||
static ArrayRef<ProcessorGroup> getProcessorGroups() {
|
||||
static llvm::ArrayRef<ProcessorGroup> getProcessorGroups() {
|
||||
auto computeGroups = []() {
|
||||
SmallVector<ProcessorGroup, 4> Groups;
|
||||
llvm::SmallVector<ProcessorGroup, 4> Groups;
|
||||
|
||||
auto HandleGroup = [&](SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *ProcInfo) {
|
||||
GROUP_RELATIONSHIP &El = ProcInfo->Group;
|
||||
@ -274,7 +275,7 @@ static ArrayRef<ProcessorGroup> getProcessorGroups() {
|
||||
return std::vector<ProcessorGroup>(Groups.begin(), Groups.end());
|
||||
};
|
||||
static auto Groups = computeGroups();
|
||||
return ArrayRef<ProcessorGroup>(Groups);
|
||||
return llvm::ArrayRef<ProcessorGroup>(Groups);
|
||||
}
|
||||
|
||||
template <typename R, typename UnaryPredicate>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user