1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Support old Mac OS X SDK and gcc

Follow up of https://github.com/ruby/ruby/pull/5927

`pthread_threadid_np()` is not even be declared in outdated SDKs.

Also, the `__API_AVAILABLE` macro does not work on gcc, which does not
support the [availability] attribute of clang, so an additional weak
symbol declaration is required to check for weakly linked symbols.

[availability]: https://clang.llvm.org/docs/AttributeReference.html#availability
This commit is contained in:
Nobuyoshi Nakada 2022-05-24 20:26:18 +09:00
parent 7d9da4c33d
commit 45177129a7
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

View file

@ -1761,13 +1761,28 @@ native_thread_native_thread_id(rb_thread_t *target_th)
return INT2FIX(tid); return INT2FIX(tid);
#elif defined(__APPLE__) #elif defined(__APPLE__)
uint64_t tid; uint64_t tid;
if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 || # if ((MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6) || \
!&pthread_threadid_np /* check weakly linked symbol */) { defined(__POWERPC__) /* never defined for PowerPC platforms */)
const bool no_pthread_threadid_np = true;
# define NO_PTHREAD_MACH_THREAD_NP 1
# elif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
const bool no_pthread_threadid_np = false;
# else
# if !(defined(__has_attribute) && __has_attribute(availability))
/* __API_AVAILABLE macro does nothing on gcc */
__attribute__((weak)) int pthread_threadid_np(pthread_t, uint64_t*);
# endif
/* Check weakly linked symbol */
const bool no_pthread_threadid_np = !&pthread_threadid_np;
# endif
if (no_pthread_threadid_np) {
return ULL2NUM(pthread_mach_thread_np(pthread_self())); return ULL2NUM(pthread_mach_thread_np(pthread_self()));
} }
# ifndef NO_PTHREAD_MACH_THREAD_NP
int e = pthread_threadid_np(target_th->nt->thread_id, &tid); int e = pthread_threadid_np(target_th->nt->thread_id, &tid);
if (e != 0) rb_syserr_fail(e, "pthread_threadid_np"); if (e != 0) rb_syserr_fail(e, "pthread_threadid_np");
return ULL2NUM((unsigned long long)tid); return ULL2NUM((unsigned long long)tid);
# endif
#endif #endif
} }
# define USE_NATIVE_THREAD_NATIVE_THREAD_ID 1 # define USE_NATIVE_THREAD_NATIVE_THREAD_ID 1