Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android < 21 must not use pthread_condattr_setclock #215

Closed
gjasny opened this issue Apr 11, 2018 · 3 comments
Closed

Android < 21 must not use pthread_condattr_setclock #215

gjasny opened this issue Apr 11, 2018 · 3 comments

Comments

@gjasny
Copy link
Contributor

gjasny commented Apr 11, 2018

Hello,

the pthread_condattr_setclock function is only available for __ANDROID_API__ >= 21. The unconditional use in pthread_helpers.hpp leads to an compile error.

What would be the proper way to handle it? Should the preprocessor condition in boost::pthread::cond_init be tightened or BOOST_THREAD_INTERNAL_CLOCK_IS_MONO not be defined on Android < 21?

Would the following patch make sense?

diff --git a/boost/thread/detail/config.hpp b/boost/thread/detail/config.hpp
index 70c74687f6..aae25268d3 100644
--- a/boost/thread/detail/config.hpp
+++ b/boost/thread/detail/config.hpp
@@ -417,6 +417,11 @@
   #define BOOST_THREAD_INTERNAL_CLOCK_IS_MONO
 #elif defined(BOOST_THREAD_CHRONO_MAC_API)
   #define BOOST_THREAD_HAS_MONO_CLOCK
+#elif defined(__ANDROID__)
+  #define BOOST_THREAD_HAS_MONO_CLOCK
+  #if defined(__ANDROID_API__) && __ANDROID_API__ >= 21
+    #define BOOST_THREAD_INTERNAL_CLOCK_IS_MONO
+  #endif
 #else
   #include <time.h> // check for CLOCK_MONOTONIC
   #if defined(CLOCK_MONOTONIC)

Thanks,
Gregor

@viboes
Copy link
Collaborator

viboes commented Apr 11, 2018

Hi,

for completion, could you add the compiler error?

Yes, please, could you provide a PR?

@gjasny
Copy link
Contributor Author

gjasny commented Apr 12, 2018

Compile error:

build	11-Apr-2018 07:46:57	clang-linux.compile.c++.without-pth /home/bamboo/bamboo-agent-home/xml-data/build-dir/EL-BOOST7-AC/_output/Applications_Android_armeabi-v7a_cxx14/boost/bin.v2/libs/type_erasure/build/clang-linux-android/debug/link-static/pch-off/target-os-android/threadapi-pthread/threading-multi/dynamic_binding.o
build	11-Apr-2018 07:46:57	In file included from libs/type_erasure/src/dynamic_binding.cpp:14:
build	11-Apr-2018 07:46:57	In file included from ./boost/thread/shared_mutex.hpp:28:
build	11-Apr-2018 07:46:57	In file included from ./boost/thread/pthread/shared_mutex.hpp:14:
build	11-Apr-2018 07:46:57	In file included from ./boost/thread/mutex.hpp:16:
build	11-Apr-2018 07:46:57	In file included from ./boost/thread/pthread/mutex.hpp:26:
build	11-Apr-2018 07:46:57	./boost/thread/pthread/pthread_helpers.hpp:28:15: error: use of undeclared identifier 'pthread_condattr_setclock'; did you mean 'pthread_condattr_setpshared'?
build	11-Apr-2018 07:46:57	              pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
build	11-Apr-2018 07:46:57	              ^~~~~~~~~~~~~~~~~~~~~~~~~
build	11-Apr-2018 07:46:57	              pthread_condattr_setpshared
build	11-Apr-2018 07:46:57	/home/bamboo/bamboo-agent-home/xml-data/build-dir/EL-BOOST7-AC/_toolchain_arm_android-14/bin/../sysroot/usr/include/pthread.h:122:5: note: 'pthread_condattr_setpshared' declared here
build	11-Apr-2018 07:46:57	int pthread_condattr_setpshared(pthread_condattr_t* __attr, int __shared);
build	11-Apr-2018 07:46:57	    ^
build	11-Apr-2018 07:46:57	1 error generated.

In pthread.h:

#if __ANDROID_API__ >= 21
int pthread_condattr_setclock(pthread_condattr_t* __attr, clockid_t __clock) __INTRODUCED_IN(21);
#endif /* __ANDROID_API__ >= 21 */

@huowa222
Copy link

in chromium build, there is a build config for android called config.gni
try to get it and refresh the value of android api level.

ry pushed a commit to denoland/chromium_build that referenced this issue Sep 10, 2019
As described in boostorg/thread#215 and
pocoproject/poco#1836, this API became
available in NDK version 21, not NDK version 20.

Change-Id: I473d19b08e7b20698eec8bc012e0035eee7070b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626298
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Charlie Andrews <charliea@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#662586}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 207d5f004073f90a2108676f547a490f10fcd7f6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants