From a28600154ac92eef7f86253bcccb5900c360c33d Mon Sep 17 00:00:00 2001 From: lateminer Date: Mon, 22 Oct 2018 00:22:54 +0300 Subject: [PATCH] Bring back SetThreadPriority --- src/compat.h | 11 +++++++++++ src/util.cpp | 13 +++++++++++++ src/util.h | 25 +------------------------ 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/compat.h b/src/compat.h index 2578d6d34..e8cdbdb4e 100644 --- a/src/compat.h +++ b/src/compat.h @@ -79,6 +79,17 @@ typedef u_int SOCKET; #define MSG_NOSIGNAL 0 #endif +#ifndef WIN32 +// PRIO_MAX is not defined on Solaris +#ifndef PRIO_MAX +#define PRIO_MAX 20 +#endif +#define THREAD_PRIORITY_LOWEST PRIO_MAX +#define THREAD_PRIORITY_BELOW_NORMAL 2 +#define THREAD_PRIORITY_NORMAL 0 +#define THREAD_PRIORITY_ABOVE_NORMAL (-2) +#endif + #if HAVE_DECL_STRNLEN == 0 size_t strnlen( const char *start, size_t max_len); #endif // HAVE_DECL_STRNLEN diff --git a/src/util.cpp b/src/util.cpp index a001de400..8b4b567b2 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -789,6 +789,19 @@ bool SetupNetworking() return true; } +void SetThreadPriority(int nPriority) +{ +#ifdef WIN32 + SetThreadPriority(GetCurrentThread(), nPriority); +#else // WIN32 +#ifdef PRIO_THREAD + setpriority(PRIO_THREAD, 0, nPriority); +#else // PRIO_THREAD + setpriority(PRIO_PROCESS, 0, nPriority); +#endif // PRIO_THREAD +#endif // WIN32 +} + int GetNumCores() { #if BOOST_VERSION >= 105600 diff --git a/src/util.h b/src/util.h index 440cb54da..12fbcb680 100644 --- a/src/util.h +++ b/src/util.h @@ -218,30 +218,7 @@ std::string HelpMessageOpt(const std::string& option, const std::string& message */ int GetNumCores(); -#ifdef WIN32 -inline void SetThreadPriority(int nPriority) -{ - SetThreadPriority(GetCurrentThread(), nPriority); -} -#else - -#define THREAD_PRIORITY_LOWEST PRIO_MAX -#define THREAD_PRIORITY_BELOW_NORMAL 2 -#define THREAD_PRIORITY_NORMAL 0 -#define THREAD_PRIORITY_ABOVE_NORMAL 0 - -inline void SetThreadPriority(int nPriority) -{ - // It's unclear if it's even possible to change thread priorities on Linux, - // but we really and truly need it for the generation threads. -#ifdef PRIO_THREAD - setpriority(PRIO_THREAD, 0, nPriority); -#else - setpriority(PRIO_PROCESS, 0, nPriority); -#endif -} -#endif - +void SetThreadPriority(int nPriority); void RenameThread(const char* name); /**