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