mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-14 09:58:50 +08:00
Merge pull request #6228 from liquid-helium/thread-pool-priority
Enabled setting thread poll priorities.
This commit is contained in:
commit
fd2f553d78
@ -36,8 +36,7 @@ class ThreadPool final : public IThreadPool, public ReferenceCounted<ThreadPool>
|
||||
~Thread() { ASSERT_ABORT(!userObject); }
|
||||
|
||||
void run() {
|
||||
deprioritizeThread();
|
||||
|
||||
setThreadPriority(pool->priority());
|
||||
threadUserObject = userObject;
|
||||
try {
|
||||
userObject->init();
|
||||
@ -62,6 +61,7 @@ class ThreadPool final : public IThreadPool, public ReferenceCounted<ThreadPool>
|
||||
enum Mode { Run = 0, Shutdown = 2 };
|
||||
volatile int mode;
|
||||
int stackSize;
|
||||
int pri;
|
||||
|
||||
struct ActionWrapper {
|
||||
PThreadAction action;
|
||||
@ -82,7 +82,7 @@ class ThreadPool final : public IThreadPool, public ReferenceCounted<ThreadPool>
|
||||
};
|
||||
|
||||
public:
|
||||
ThreadPool(int stackSize) : dontstop(ios), mode(Run), stackSize(stackSize) {}
|
||||
ThreadPool(int stackSize, int pri) : dontstop(ios), mode(Run), stackSize(stackSize), pri(pri) {}
|
||||
~ThreadPool() override {}
|
||||
Future<Void> stop(Error const& e = success()) override {
|
||||
if (mode == Shutdown)
|
||||
@ -111,10 +111,11 @@ public:
|
||||
threads.back()->handle = g_network->startThread(start, threads.back(), stackSize, name);
|
||||
}
|
||||
void post(PThreadAction action) override { ios.post(ActionWrapper(action)); }
|
||||
int priority() const { return pri; }
|
||||
};
|
||||
|
||||
Reference<IThreadPool> createGenericThreadPool(int stackSize) {
|
||||
return Reference<IThreadPool>(new ThreadPool(stackSize));
|
||||
Reference<IThreadPool> createGenericThreadPool(int stackSize, int pri) {
|
||||
return Reference<IThreadPool>(new ThreadPool(stackSize, pri));
|
||||
}
|
||||
|
||||
thread_local IThreadPoolReceiver* ThreadPool::Thread::threadUserObject;
|
||||
|
@ -141,7 +141,7 @@ private:
|
||||
PromiseStream<T> promiseStream;
|
||||
};
|
||||
|
||||
Reference<IThreadPool> createGenericThreadPool(int stackSize = 0);
|
||||
Reference<IThreadPool> createGenericThreadPool(int stackSize = 0, int pri = 10);
|
||||
|
||||
class DummyThreadPool final : public IThreadPool, ReferenceCounted<DummyThreadPool> {
|
||||
public:
|
||||
|
@ -2772,10 +2772,10 @@ void waitThread(THREAD_HANDLE thread) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void deprioritizeThread() {
|
||||
void setThreadPriority(int pri) {
|
||||
#ifdef __linux__
|
||||
int tid = syscall(SYS_gettid);
|
||||
setpriority(PRIO_PROCESS, tid, 10);
|
||||
setpriority(PRIO_PROCESS, tid, pri);
|
||||
#elif defined(_WIN32)
|
||||
#endif
|
||||
}
|
||||
|
@ -187,8 +187,8 @@ THREAD_HANDLE startThread(void*(func)(void*), void* arg, int stackSize = 0, cons
|
||||
|
||||
void waitThread(THREAD_HANDLE thread);
|
||||
|
||||
// Linux-only for now. Set thread priority "low"
|
||||
void deprioritizeThread();
|
||||
// Linux-only for now. Set thread priority.
|
||||
void setThreadPriority(int pri);
|
||||
|
||||
#define DEBUG_DETERMINISM 0
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user