This commit is contained in:
Samuel Thibault 2025-06-02 21:54:12 +03:00 committed by GitHub
commit 1355efc265
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 4 deletions

View file

@ -801,6 +801,15 @@ case "${host}" in
AC_DEFINE([JEMALLOC_THREADED_INIT], [ ], [ ])
AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ], [ ])
;;
*-*-gnu*)
dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
JE_APPEND_VS(CPPFLAGS, -DPATH_MAX=8192)
abi="elf"
AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
;;
*-*-netbsd*)
AC_MSG_CHECKING([ABI])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
@ -2100,6 +2109,15 @@ dnl Check if we have dlsym support.
fi
fi
dnl Check if pthread_getaffinity_np exists (does not on GNU Hurd)
AC_CHECK_FUNC([pthread_getaffinity_np],
[have_pthread_getaffinity_np="1"],
[have_pthread_getaffinity_np="0"]
)
if test "x$have_pthread_getaffinity_np" = "x1" ; then
AC_DEFINE([JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP], [ ])
fi
JE_APPEND_VS(CPPFLAGS, -D_REENTRANT)
dnl Check whether clock_gettime(2) is in libc or librt.

View file

@ -119,7 +119,7 @@ set_current_thread_affinity(int cpu) {
#if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY) || defined(JEMALLOC_HAVE_PTHREAD_SETAFFINITY_NP)
#if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY)
cpu_set_t cpuset;
#else
#elif defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
# ifndef __NetBSD__
cpuset_t cpuset;
# else
@ -127,16 +127,20 @@ set_current_thread_affinity(int cpu) {
# endif
#endif
#if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY) || defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
#ifndef __NetBSD__
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
#else
cpuset = cpuset_create();
#endif
#else
return 1;
#endif
#if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY)
return (sched_setaffinity(0, sizeof(cpu_set_t), &cpuset) != 0);
#else
#elif defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
# ifndef __NetBSD__
int ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset_t),
&cpuset);

View file

@ -765,8 +765,11 @@ malloc_ncpus(void) {
# endif
# if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY)
sched_getaffinity(0, sizeof(set), &set);
# else
# elif defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
pthread_getaffinity_np(pthread_self(), sizeof(set), &set);
# else
CPU_ZERO(&set);
CPU_SET(0, &set);
# endif
result = CPU_COUNT(&set);
}
@ -802,8 +805,11 @@ malloc_cpu_count_is_deterministic(void)
# endif /* __FreeBSD__ */
# if defined(JEMALLOC_HAVE_SCHED_SETAFFINITY)
sched_getaffinity(0, sizeof(set), &set);
# else /* !JEMALLOC_HAVE_SCHED_SETAFFINITY */
# elif defined(JEMALLOC_HAVE_PTHREAD_GETAFFINITY_NP)
pthread_getaffinity_np(pthread_self(), sizeof(set), &set);
# else
CPU_ZERO(&set);
CPU_SET(0, &set);
# endif /* JEMALLOC_HAVE_SCHED_SETAFFINITY */
long cpu_affinity = CPU_COUNT(&set);
if (cpu_affinity != cpu_conf) {