diff --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp index 9da357a7ebb9..90352d2f212a 100644 --- a/llvm/lib/Support/Threading.cpp +++ b/llvm/lib/Support/Threading.cpp @@ -20,8 +20,6 @@ #include #include -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 diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc index 27cbb180e57a..4967d3f8c0ef 100644 --- a/llvm/lib/Support/Unix/Threading.inc +++ b/llvm/lib/Support/Unix/Threading.inc @@ -33,12 +33,7 @@ #include // 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 @@ -278,7 +273,8 @@ void llvm::get_thread_name(SmallVectorImpl &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 strs; + llvm::SmallVector 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 Data = Line.split(':'); + for (llvm::StringRef Line : strs) { + std::pair 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. diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc index 86e46b99cb38..26dabee1bd6a 100644 --- a/llvm/lib/Support/Windows/Threading.inc +++ b/llvm/lib/Support/Windows/Threading.inc @@ -105,7 +105,8 @@ void llvm::get_thread_name(SmallVectorImpl &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> getActiveGroups() { return Groups; } -static ArrayRef getProcessorGroups() { +static llvm::ArrayRef getProcessorGroups() { auto computeGroups = []() { - SmallVector Groups; + llvm::SmallVector Groups; auto HandleGroup = [&](SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *ProcInfo) { GROUP_RELATIONSHIP &El = ProcInfo->Group; @@ -274,7 +275,7 @@ static ArrayRef getProcessorGroups() { return std::vector(Groups.begin(), Groups.end()); }; static auto Groups = computeGroups(); - return ArrayRef(Groups); + return llvm::ArrayRef(Groups); } template