From 39ca0b58c986f6d5fb295c4a09b87a2f48b5d482 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sun, 8 Oct 2017 11:43:32 +0300 Subject: [PATCH] Fix 'pthread_np.h: no such file' compiler error on kFreeBSD (fix commit 49d7fe7) Issue #180 (bdwgc). * include/private/gcconfig.h [(FREEBSD && __GLIBC__ || LINUX || PLATFORM_ANDROID) && !NO_PTHREAD_GETATTR_NP] (HAVE_PTHREAD_GETATTR_NP): New macro. * include/private/gcconfig.h [FREEBSD && !__GLIBC__ && !NO_PTHREAD_ATTR_GET_NP] (HAVE_PTHREAD_NP_H, HAVE_PTHREAD_ATTR_GET_NP): Likewise. * os_dep.c [!BEOS && !AMIGA && !OS2 && !MSWIN32 && !MSWINCE && !CYGWIN32 && !GC_OPENBSD_THREADS] (include pthread.h, include pthread_np.h, GC_get_main_stack_base): Check presence of HAVE_PTHREAD_ATTR_GET_NP, HAVE_PTHREAD_GETATTR_NP, HAVE_PTHREAD_NP_H macros instead of FREEBSD, NO_PTHREAD_ATTR_GET_NP, LINUX, PLATFORM_ANDROID, NO_PTHREAD_GETATTR_NP. * os_dep.c [!HAVE_GET_STACK_BASE] (GC_get_stack_base): Check presence of THREADS, HAVE_PTHREAD_ATTR_GET_NP, HAVE_PTHREAD_GETATTR_NP, HAVE_PTHREAD_NP_H macros instead of GC_FREEBSD_THREADS, NO_PTHREAD_ATTR_GET_NP, GC_LINUX_THREADS, PLATFORM_ANDROID, NO_PTHREAD_GETATTR_NP, FREEBSD. --- include/private/gcconfig.h | 11 +++++++++++ os_dep.c | 32 ++++++++++++++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 33b482c1..7fb63e0c 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -3027,6 +3027,17 @@ # define USE_GET_STACKBASE_FOR_MAIN #endif +/* Outline pthread primitives to use in GC_get_[main_]stack_base. */ +#if ((defined(FREEBSD) && defined(__GLIBC__)) /* kFreeBSD */ \ + || defined(LINUX) || defined(PLATFORM_ANDROID)) \ + && !defined(NO_PTHREAD_GETATTR_NP) +# define HAVE_PTHREAD_GETATTR_NP 1 +#elif defined(FREEBSD) && !defined(__GLIBC__) \ + && !defined(NO_PTHREAD_ATTR_GET_NP) +# define HAVE_PTHREAD_NP_H 1 /* requires include pthread_np.h */ +# define HAVE_PTHREAD_ATTR_GET_NP 1 +#endif + #if defined(UNIX_LIKE) && defined(THREADS) && !defined(NO_CANCEL_SAFE) \ && !defined(PLATFORM_ANDROID) /* Make the code cancellation-safe. This basically means that we */ diff --git a/os_dep.c b/os_dep.c index 4efd6732..6b009fca 100644 --- a/os_dep.c +++ b/os_dep.c @@ -1182,12 +1182,12 @@ GC_INNER size_t GC_page_size = 0; && !defined(GC_OPENBSD_THREADS) \ && (!defined(GC_SOLARIS_THREADS) || defined(_STRICT_STDC)) -# if defined(FREEBSD) && !defined(NO_PTHREAD_ATTR_GET_NP) \ +# if (defined(HAVE_PTHREAD_ATTR_GET_NP) || defined(HAVE_PTHREAD_GETATTR_NP)) \ && (defined(THREADS) || defined(USE_GET_STACKBASE_FOR_MAIN)) # include -# include /* for pthread_attr_get_np() */ -# elif defined(LINUX) && defined(USE_GET_STACKBASE_FOR_MAIN) -# include +# ifdef HAVE_PTHREAD_NP_H +# include /* for pthread_attr_get_np() */ +# endif # elif defined(DARWIN) && !defined(NO_PTHREAD_GET_STACKADDR_NP) /* We could use pthread_get_stackaddr_np even in case of a */ /* single-threaded gclib (there is no -lpthread on Darwin). */ @@ -1199,19 +1199,19 @@ GC_INNER size_t GC_page_size = 0; ptr_t GC_get_main_stack_base(void) { ptr_t result; -# if ((defined(FREEBSD) && !defined(NO_PTHREAD_ATTR_GET_NP)) \ - || (defined(LINUX) && !defined(NO_PTHREAD_GETATTR_NP))) \ +# if (defined(HAVE_PTHREAD_ATTR_GET_NP) \ + || defined(HAVE_PTHREAD_GETATTR_NP)) \ && (defined(USE_GET_STACKBASE_FOR_MAIN) \ || (defined(THREADS) && !defined(REDIRECT_MALLOC))) pthread_attr_t attr; void *stackaddr; size_t size; -# ifdef FREEBSD +# ifdef HAVE_PTHREAD_ATTR_GET_NP if (pthread_attr_init(&attr) == 0 && (pthread_attr_get_np(pthread_self(), &attr) == 0 ? TRUE : (pthread_attr_destroy(&attr), FALSE))) -# else /* LINUX */ +# else /* HAVE_PTHREAD_GETATTR_NP */ if (pthread_getattr_np(pthread_self(), &attr) == 0) # endif { @@ -1280,12 +1280,12 @@ GC_INNER size_t GC_page_size = 0; # define GET_MAIN_STACKBASE_SPECIAL #endif /* !AMIGA, !BEOS, !OPENBSD, !OS2, !Windows */ -#if (defined(GC_FREEBSD_THREADS) && !defined(NO_PTHREAD_ATTR_GET_NP)) \ - || ((defined(GC_LINUX_THREADS) || defined(PLATFORM_ANDROID)) \ - && !defined(NO_PTHREAD_GETATTR_NP)) - +#if (defined(HAVE_PTHREAD_ATTR_GET_NP) || defined(HAVE_PTHREAD_GETATTR_NP)) \ + && defined(THREADS) && !defined(HAVE_GET_STACK_BASE) # include - /* extern int pthread_getattr_np(pthread_t, pthread_attr_t *); */ +# ifdef HAVE_PTHREAD_NP_H +# include +# endif GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *b) { @@ -1295,7 +1295,7 @@ GC_INNER size_t GC_page_size = 0; DCL_LOCK_STATE; # endif -# ifdef FREEBSD +# ifdef HAVE_PTHREAD_ATTR_GET_NP if (pthread_attr_init(&attr) != 0) ABORT("pthread_attr_init failed"); if (pthread_attr_get_np(pthread_self(), &attr) != 0) { @@ -1303,7 +1303,7 @@ GC_INNER size_t GC_page_size = 0; (void)pthread_attr_destroy(&attr); return GC_UNIMPLEMENTED; } -# else /* LINUX */ +# else /* HAVE_PTHREAD_GETATTR_NP */ if (pthread_getattr_np(pthread_self(), &attr) != 0) { WARN("pthread_getattr_np failed\n", 0); return GC_UNIMPLEMENTED; @@ -1344,7 +1344,7 @@ GC_INNER size_t GC_page_size = 0; return GC_SUCCESS; } # define HAVE_GET_STACK_BASE -#endif /* GC_LINUX_THREADS */ +#endif /* THREADS && (HAVE_PTHREAD_ATTR_GET_NP || HAVE_PTHREAD_GETATTR_NP) */ #if defined(GC_DARWIN_THREADS) && !defined(NO_PTHREAD_GET_STACKADDR_NP) # include -- 2.40.0