diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 3e1eb14a6a1..81d9f3e7b0f 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -47,7 +47,8 @@ class Math { public: Math() {} // useless to instance - static const uint64_t RANDOM_MAX = 0xFFFFFFFF; + // Not using 'RANDOM_MAX' to avoid conflict with system headers on some OSes (at least NetBSD). + static const uint64_t RANDOM_32BIT_MAX = 0xFFFFFFFF; static _ALWAYS_INLINE_ double sin(double p_x) { return ::sin(p_x); } static _ALWAYS_INLINE_ float sin(float p_x) { return ::sinf(p_x); } @@ -280,8 +281,8 @@ public: static void randomize(); static uint32_t rand_from_seed(uint64_t *seed); static uint32_t rand(); - static _ALWAYS_INLINE_ double randd() { return (double)rand() / (double)Math::RANDOM_MAX; } - static _ALWAYS_INLINE_ float randf() { return (float)rand() / (float)Math::RANDOM_MAX; } + static _ALWAYS_INLINE_ double randd() { return (double)rand() / (double)Math::RANDOM_32BIT_MAX; } + static _ALWAYS_INLINE_ float randf() { return (float)rand() / (float)Math::RANDOM_32BIT_MAX; } static double random(double from, double to); static float random(float from, float to); diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h index ac65ce3509c..6402ebd5546 100644 --- a/core/math/random_pcg.h +++ b/core/math/random_pcg.h @@ -67,7 +67,6 @@ class RandomPCG { public: static const uint64_t DEFAULT_SEED = 12047754176567800795U; static const uint64_t DEFAULT_INC = PCG_DEFAULT_INC_64; - static const uint64_t RANDOM_MAX = 0xFFFFFFFF; RandomPCG(uint64_t p_seed = DEFAULT_SEED, uint64_t p_inc = DEFAULT_INC); diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp index 21f49a7e381..b308f75b800 100644 --- a/drivers/unix/thread_posix.cpp +++ b/drivers/unix/thread_posix.cpp @@ -29,17 +29,17 @@ /*************************************************************************/ #include "thread_posix.h" -#include "core/script_language.h" #if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(NO_THREADS) +#include "core/os/memory.h" +#include "core/safe_refcount.h" +#include "core/script_language.h" + #ifdef PTHREAD_BSD_SET_NAME #include #endif -#include "core/os/memory.h" -#include "core/safe_refcount.h" - static void _thread_id_key_destr_callback(void *p_value) { memdelete(static_cast(p_value)); } @@ -130,6 +130,8 @@ Error ThreadPosix::set_name_func_posix(const String &p_name) { #ifdef PTHREAD_BSD_SET_NAME pthread_set_name_np(running_thread, p_name.utf8().get_data()); int err = 0; // Open/FreeBSD ignore errors in this function +#elif defined(PTHREAD_NETBSD_SET_NAME) + int err = pthread_setname_np(running_thread, "%s", const_cast(p_name.utf8().get_data())); #else int err = pthread_setname_np(running_thread, p_name.utf8().get_data()); #endif // PTHREAD_BSD_SET_NAME diff --git a/platform/server/platform_config.h b/platform/server/platform_config.h index bdff93f02bf..73136ec81b9 100644 --- a/platform/server/platform_config.h +++ b/platform/server/platform_config.h @@ -31,10 +31,19 @@ #if defined(__linux__) || defined(__APPLE__) #include #endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) -#include + +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#include // alloca +// FreeBSD and OpenBSD use pthread_set_name_np, while other platforms, +// include NetBSD, use pthread_setname_np. NetBSD's version however requires +// a different format, we handle this directly in thread_posix. +#ifdef __NetBSD__ +#define PTHREAD_NETBSD_SET_NAME +#else #define PTHREAD_BSD_SET_NAME #endif +#endif + #ifdef __APPLE__ #define PTHREAD_RENAME_SELF #endif diff --git a/platform/x11/platform_config.h b/platform/x11/platform_config.h index c905ddb2365..0bd865ef742 100644 --- a/platform/x11/platform_config.h +++ b/platform/x11/platform_config.h @@ -31,10 +31,18 @@ #ifdef __linux__ #include #endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) -#include + +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#include // alloca +// FreeBSD and OpenBSD use pthread_set_name_np, while other platforms, +// include NetBSD, use pthread_setname_np. NetBSD's version however requires +// a different format, we handle this directly in thread_posix. +#ifdef __NetBSD__ +#define PTHREAD_NETBSD_SET_NAME +#else #define PTHREAD_BSD_SET_NAME #endif +#endif #define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h" #define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h"