mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-14 06:48:39 -04:00
Set worker threads to background mode on Windows if niceness > 0
This commit is contained in:
parent
3b39b319b4
commit
3dba17ea76
@ -33,6 +33,7 @@
|
||||
|
||||
#include <folly/Conv.h>
|
||||
#include <folly/portability/PThread.h>
|
||||
#include <folly/portability/Windows.h>
|
||||
#include <folly/system/ThreadName.h>
|
||||
|
||||
#include "dwarfs/error.h"
|
||||
@ -109,11 +110,11 @@ class basic_worker_group final : public worker_group::impl, private Policy {
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num_workers; ++i) {
|
||||
workers_.emplace_back([this, /*niceness,*/ group_name, i] {
|
||||
workers_.emplace_back([this, niceness, group_name, i] {
|
||||
folly::setThreadName(folly::to<std::string>(group_name, i + 1));
|
||||
// TODO: FIXME: this is broken
|
||||
// [[maybe_unused]] auto rv = ::nice(niceness);
|
||||
do_work();
|
||||
do_work(niceness > 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -220,7 +221,10 @@ class basic_worker_group final : public worker_group::impl, private Policy {
|
||||
private:
|
||||
using jobs_t = std::queue<worker_group::job_t>;
|
||||
|
||||
void do_work() {
|
||||
void do_work(bool is_background [[maybe_unused]]) {
|
||||
#ifdef _WIN32
|
||||
auto hthr = ::GetCurrentThread();
|
||||
#endif
|
||||
for (;;) {
|
||||
worker_group::job_t job;
|
||||
|
||||
@ -246,7 +250,17 @@ class basic_worker_group final : public worker_group::impl, private Policy {
|
||||
|
||||
{
|
||||
typename Policy::task task(this);
|
||||
#ifdef _WIN32
|
||||
if (is_background) {
|
||||
::SetThreadPriority(hthr, THREAD_MODE_BACKGROUND_BEGIN);
|
||||
}
|
||||
#endif
|
||||
job();
|
||||
#ifdef _WIN32
|
||||
if (is_background) {
|
||||
::SetThreadPriority(hthr, THREAD_MODE_BACKGROUND_END);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user