Enable using threads on z/OS (#171847)

z/OS 3.1 enables TLS support (limited to compile time constant
initializers). To enable building with thread support, we need to update
the code to handle the difference in definition of pthread_t. It is a
struct on z/OS, not an integer. The existing code assumes that pthread_t
is an integer. This usually happens when checking to see if pthread_t is
null or not.

In Parallel.cpp, there was a variable `Backoff` defined as TLS. The
initializer for this requires C++ initialization which isn't supported
on z/OS. The variable isn't actually used (see declaration of local var
with same name inside the loop) so deleting it solved the build failure
this was causing.
This commit is contained in:
Sean Perry
2026-01-15 15:49:45 -05:00
committed by GitHub
parent edd857aad8
commit 64be34c562
4 changed files with 19 additions and 12 deletions

View File

@@ -597,12 +597,7 @@ option(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON)
option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON)
# On z/OS, threads cannot be used because TLS is not supported.
if (CMAKE_SYSTEM_NAME MATCHES "OS390")
option(LLVM_ENABLE_THREADS "Use threads if available." OFF)
else()
option(LLVM_ENABLE_THREADS "Use threads if available." ON)
endif()
option(LLVM_ENABLE_THREADS "Use threads if available." ON)
set(LLVM_ENABLE_ICU "OFF" CACHE STRING "Use ICU for text encoding conversion support if available. Can be ON, OFF, or FORCE_ON")

View File

@@ -51,7 +51,11 @@ class thread {
public:
#ifdef LLVM_ON_UNIX
using native_handle_type = pthread_t;
#ifdef __MVS__
using id = unsigned long long;
#else
using id = pthread_t;
#endif
using start_routine_type = void *(*)(void *);
template <typename CalleeTuple> static void *ThreadProxy(void *Ptr) {
@@ -97,7 +101,7 @@ public:
return *this;
}
bool joinable() const noexcept { return Thread != native_handle_type(); }
bool joinable() const noexcept { return get_id() != 0; }
inline id get_id() const noexcept;
@@ -133,7 +137,7 @@ thread::thread(std::optional<unsigned> StackSizeInBytes, Function &&f,
Thread = llvm_execute_on_thread_impl(ThreadProxy<CalleeTuple>, Callee.get(),
StackSizeInBytes);
if (Thread != native_handle_type())
if (joinable())
Callee.release();
}

View File

@@ -129,8 +129,6 @@ private:
// first successful tryAcquire() in a process. This guarantees forward
// progress without requiring a dedicated "always-on" thread here.
static thread_local std::unique_ptr<ExponentialBackoff> Backoff;
while (true) {
if (TheJobserver) {
// Jobserver-mode scheduling:

View File

@@ -119,9 +119,17 @@ void llvm_thread_join_impl(pthread_t Thread) {
}
}
pthread_t llvm_thread_get_id_impl(pthread_t Thread) { return Thread; }
llvm::thread::id llvm_thread_get_id_impl(pthread_t Thread) {
#ifdef __MVS__
return Thread.__;
#else
return Thread;
#endif
}
pthread_t llvm_thread_get_current_id_impl() { return ::pthread_self(); }
llvm::thread::id llvm_thread_get_current_id_impl() {
return llvm_thread_get_id_impl(::pthread_self());
}
} // namespace llvm
@@ -148,6 +156,8 @@ uint64_t llvm::get_threadid() {
return uint64_t(syscall(__NR_gettid));
#elif defined(_AIX)
return uint64_t(thread_self());
#elif defined(__MVS__)
return llvm_thread_get_id_impl(pthread_self());
#else
return uint64_t(pthread_self());
#endif