Fix build issues for musl libc (#267)
Change-Id: Ia31330b0f96669966712b58986abeca754c2cbb9
This commit is contained in:
committed by
David Yat Sin
parent
d159b29dc6
commit
5d04bd42f3
@@ -109,6 +109,18 @@ if ( HAVE_MEMFD_CREATE )
|
||||
target_compile_definitions(${CORE_RUNTIME_TARGET} PRIVATE HAVE_MEMFD_CREATE )
|
||||
endif()
|
||||
|
||||
## Check for _GNU_SOURCE pthread extensions
|
||||
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
|
||||
CHECK_SYMBOL_EXISTS ( "pthread_attr_setaffinity_np" "pthread.h" HAVE_PTHREAD_ATTR_SETAFFINITY_NP )
|
||||
CHECK_SYMBOL_EXISTS ( "pthread_rwlockattr_setkind_np" "pthread.h" HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP )
|
||||
unset(CMAKE_REQUIRED_DEFINITIONS)
|
||||
if ( HAVE_PTHREAD_ATTR_SETAFFINITY_NP )
|
||||
target_compile_definitions(${CORE_RUNTIME_TARGET} PRIVATE HAVE_PTHREAD_ATTR_SETAFFINITY_NP )
|
||||
endif()
|
||||
if ( HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP )
|
||||
target_compile_definitions(${CORE_RUNTIME_TARGET} PRIVATE HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP )
|
||||
endif()
|
||||
|
||||
## Set include directories for ROCr runtime
|
||||
target_include_directories( ${CORE_RUNTIME_TARGET}
|
||||
PUBLIC
|
||||
|
||||
@@ -138,12 +138,14 @@ class os_thread {
|
||||
for (int i = 0; i < cores; i++) {
|
||||
CPU_SET_S(i, CPU_ALLOC_SIZE(cores), cpuset);
|
||||
}
|
||||
#ifdef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
|
||||
err = pthread_attr_setaffinity_np(&attrib, CPU_ALLOC_SIZE(cores), cpuset);
|
||||
CPU_FREE(cpuset);
|
||||
if (err != 0) {
|
||||
fprintf(stderr, "pthread_setaffinity_np failed: %s\n", strerror(err));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -166,6 +168,17 @@ class os_thread {
|
||||
}
|
||||
} while (stackSize < 20 * 1024 * 1024);
|
||||
|
||||
#ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
|
||||
if (cores && cpuset) {
|
||||
err = pthread_setaffinity_np(thread, CPU_ALLOC_SIZE(cores), cpuset);
|
||||
CPU_FREE(cpuset);
|
||||
if (err != 0) {
|
||||
fprintf(stderr, "pthread_setaffinity_np failed: %s\n", strerror(err));
|
||||
thread = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
struct sched_param param = {};
|
||||
if (priority != OS_THREAD_PRIORITY_DEFAULT) {
|
||||
int set_priority;
|
||||
@@ -696,18 +709,12 @@ SharedMutex CreateSharedMutex() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#ifdef HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP
|
||||
err = pthread_rwlockattr_setkind_np(&attrib, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
|
||||
if (err != 0) {
|
||||
fprintf(stderr, "Set rw lock attribute failure: %s\n", strerror(err));
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
err = pthread_rwlockattr_setkind(&attrib, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
|
||||
if (err != 0) {
|
||||
fprintf(stderr, "Set rw lock attribute failure: %s\n", strerror(err));
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
pthread_rwlock_t* lock = new pthread_rwlock_t;
|
||||
|
||||
Reference in New Issue
Block a user