summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Carlier <frederik.carlier@quamotion.mobi>2017-01-27 10:37:49 +0100
committerJan Vorlicek <janvorli@microsoft.com>2017-01-27 10:37:49 +0100
commit6ee7c2074cb6e9be0425af981c08593fd505f723 (patch)
tree6efc4fad97f429b10715bfc95ccbc262ebcf599f
parentb462e748844f61726c51b0e1792c004cf7c7647f (diff)
downloadcoreclr-6ee7c2074cb6e9be0425af981c08593fd505f723.tar.gz
coreclr-6ee7c2074cb6e9be0425af981c08593fd505f723.tar.bz2
coreclr-6ee7c2074cb6e9be0425af981c08593fd505f723.zip
Support platforms where pthread is part of libc (#9154)
* Make threading code compatible with Android
-rw-r--r--src/pal/src/config.h.in1
-rw-r--r--src/pal/src/configure.cmake33
-rw-r--r--src/pal/src/include/pal/threadsusp.hpp2
3 files changed, 26 insertions, 10 deletions
diff --git a/src/pal/src/config.h.in b/src/pal/src/config.h.in
index 4d21fb70e4..77d7bfaf5a 100644
--- a/src/pal/src/config.h.in
+++ b/src/pal/src/config.h.in
@@ -51,6 +51,7 @@
#cmakedefine01 HAVE_MACH_EXCEPTIONS
#cmakedefine01 HAVE_VM_ALLOCATE
#cmakedefine01 HAVE_VM_READ
+#cmakedefine01 HAVE_SEMAPHORE_H
#cmakedefine01 HAS_SYSV_SEMAPHORES
#cmakedefine01 HAS_PTHREAD_MUTEXES
#cmakedefine01 HAVE_TTRACE
diff --git a/src/pal/src/configure.cmake b/src/pal/src/configure.cmake
index a53e0db51e..4f2bc5739b 100644
--- a/src/pal/src/configure.cmake
+++ b/src/pal/src/configure.cmake
@@ -33,6 +33,7 @@ check_include_files(sys/lwp.h HAVE_SYS_LWP_H)
check_include_files(lwp.h HAVE_LWP_H)
check_include_files(libunwind.h HAVE_LIBUNWIND_H)
check_include_files(runetype.h HAVE_RUNETYPE_H)
+check_include_files(semaphore.h HAVE_SEMAPHORE_H)
if(NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD AND NOT CMAKE_SYSTEM_NAME STREQUAL NetBSD)
set(CMAKE_REQUIRED_FLAGS "-ldl")
@@ -48,15 +49,26 @@ check_include_files(gnu/lib-names.h HAVE_GNU_LIBNAMES_H)
check_function_exists(kqueue HAVE_KQUEUE)
check_function_exists(getpwuid_r HAVE_GETPWUID_R)
-check_library_exists(pthread pthread_suspend "" HAVE_PTHREAD_SUSPEND)
-check_library_exists(pthread pthread_suspend_np "" HAVE_PTHREAD_SUSPEND_NP)
-check_library_exists(pthread pthread_continue "" HAVE_PTHREAD_CONTINUE)
-check_library_exists(pthread pthread_continue_np "" HAVE_PTHREAD_CONTINUE_NP)
-check_library_exists(pthread pthread_resume_np "" HAVE_PTHREAD_RESUME_NP)
-check_library_exists(pthread pthread_attr_get_np "" HAVE_PTHREAD_ATTR_GET_NP)
-check_library_exists(pthread pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP)
-check_library_exists(pthread pthread_getcpuclockid "" HAVE_PTHREAD_GETCPUCLOCKID)
-check_library_exists(pthread pthread_sigqueue "" HAVE_PTHREAD_SIGQUEUE)
+
+check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
+check_library_exists(c pthread_create "" HAVE_PTHREAD_IN_LIBC)
+
+if (HAVE_LIBPTHREAD)
+ set(PTHREAD_LIBRARY pthread)
+elseif (HAVE_PTHREAD_IN_LIBC)
+ set(PTHREAD_LIBRARY c)
+endif()
+
+check_library_exists(${PTHREAD_LIBRARY} pthread_suspend "" HAVE_PTHREAD_SUSPEND)
+check_library_exists(${PTHREAD_LIBRARY} pthread_suspend_np "" HAVE_PTHREAD_SUSPEND_NP)
+check_library_exists(${PTHREAD_LIBRARY} pthread_continue "" HAVE_PTHREAD_CONTINUE)
+check_library_exists(${PTHREAD_LIBRARY} pthread_continue_np "" HAVE_PTHREAD_CONTINUE_NP)
+check_library_exists(${PTHREAD_LIBRARY} pthread_resume_np "" HAVE_PTHREAD_RESUME_NP)
+check_library_exists(${PTHREAD_LIBRARY} pthread_attr_get_np "" HAVE_PTHREAD_ATTR_GET_NP)
+check_library_exists(${PTHREAD_LIBRARY} pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP)
+check_library_exists(${PTHREAD_LIBRARY} pthread_getcpuclockid "" HAVE_PTHREAD_GETCPUCLOCKID)
+check_library_exists(${PTHREAD_LIBRARY} pthread_sigqueue "" HAVE_PTHREAD_SIGQUEUE)
+
check_function_exists(sigreturn HAVE_SIGRETURN)
check_function_exists(_thread_sys_sigreturn HAVE__THREAD_SYS_SIGRETURN)
set(CMAKE_REQUIRED_LIBRARIES m)
@@ -874,7 +886,8 @@ int main(void)
unlink(szFileName);
exit(ret);
}" UNGETC_NOT_RETURN_EOF)
-set(CMAKE_REQUIRED_LIBRARIES pthread)
+
+set(CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARY})
check_cxx_source_runs("
#include <stdlib.h>
#include <errno.h>
diff --git a/src/pal/src/include/pal/threadsusp.hpp b/src/pal/src/include/pal/threadsusp.hpp
index e1e85e265c..dfd65d0f8b 100644
--- a/src/pal/src/include/pal/threadsusp.hpp
+++ b/src/pal/src/include/pal/threadsusp.hpp
@@ -55,6 +55,8 @@ Abstract:
#if HAVE_SYS_SEMAPHORE_H
#include <sys/semaphore.h>
+#elif HAVE_SEMAPHORE_H
+#include <semaphore.h>
#endif // HAVE_SYS_SEMAPHORE_H
#elif HAS_PTHREAD_MUTEXES && HAVE_MACH_EXCEPTIONS