ccls/src/work_thread.cc

27 lines
657 B
C++
Raw Normal View History

2017-09-13 03:35:27 +00:00
#include "work_thread.h"
#include "platform.h"
std::atomic<int> WorkThread::num_active_threads;
std::atomic<bool> WorkThread::request_exit_on_idle;
// static
2017-09-22 01:14:57 +00:00
void WorkThread::StartThread(const std::string& thread_name,
const std::function<Result()>& entry_point) {
2017-09-13 03:35:27 +00:00
new std::thread([thread_name, entry_point]() {
SetCurrentThreadName(thread_name);
++num_active_threads;
// Main loop.
while (true) {
Result result = entry_point();
if (result == Result::ExitThread)
break;
if (request_exit_on_idle && result == Result::NoWork)
break;
}
--num_active_threads;
});
}