Skip to content

Conversation

vvydria
Copy link

@vvydria vvydria commented Feb 17, 2025

Improvements.

Android and Apple support none-portable functions for monotonic pthread cond wait.

Apple supports pthread_cond_timedwait_relative_np since macos(10.4) and ios(2.0): https://github.com/apple/darwin-libpthread/blob/main/include/pthread/pthread.h#L532

Android up to __ANDROID_API__ < 21 supports pthread_cond_timedwait_monotonic_np and pthread_cond_timedwait_relative_np.

Note that in some versions of the NDK, these symbols were removed from the header file(https://android.googlesource.com/platform/bionic/+/refs/heads/ndk-r13-release/libc/include/pthread.h) although they were present in the libc.map( https://android.googlesource.com/platform/bionic/+/refs/heads/ndk-r13-release/libc/libc.map.txt#779) and cpp(https://android.googlesource.com/platform/bionic/+/refs/heads/ndk-r13-release/libc/bionic/pthread_cond.cpp#221).

A workaround is to declare these functions as follows:
extern "C" int pthread_cond_timedwait_[monotonic|relative]_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);

See related comments on this: https://android.googlesource.com/platform/bionic.git/+/refs/heads/ndk-release-r16/libc/include/pthread.h#162

Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant