Skip to content

Commit

Permalink
Move SetThreadPriority implementation to util.cpp instead of the header
Browse files Browse the repository at this point in the history
Put the THREAD_* and PRIO_ constants in compat.h.
  • Loading branch information
laanwj committed Aug 26, 2014
1 parent f780e65 commit 610a8c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
11 changes: 11 additions & 0 deletions src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@ typedef u_int SOCKET;
#define SOCKET_ERROR -1
#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

#endif // _BITCOIN_COMPAT_H
13 changes: 13 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,3 +1286,16 @@ std::string FormatParagraph(const std::string in, size_t width, size_t indent)
}
return out.str();
}

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
}
29 changes: 1 addition & 28 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,34 +342,7 @@ bool TimingResistantEqual(const T& a, const T& b)
return accumulator == 0;
}

#ifdef WIN32
inline void SetThreadPriority(int nPriority)
{
SetThreadPriority(GetCurrentThread(), nPriority);
}
#else

// 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)

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);

// Standard wrapper for do-something-forever thread functions.
Expand Down

0 comments on commit 610a8c0

Please sign in to comment.