mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-25 21:06:58 -05:00
common/thread_worker: Simplify logic
This commit is contained in:
parent
a10e112e64
commit
c147e9a90e
1 changed files with 1 additions and 8 deletions
|
@ -12,13 +12,6 @@ ThreadWorker::ThreadWorker(std::size_t num_workers, const std::string& name) {
|
||||||
const auto lambda = [this, thread_name{std::string{name}}] {
|
const auto lambda = [this, thread_name{std::string{name}}] {
|
||||||
Common::SetCurrentThreadName(thread_name.c_str());
|
Common::SetCurrentThreadName(thread_name.c_str());
|
||||||
|
|
||||||
// TODO(Blinkhawk): Change the design, this is very prone to data races
|
|
||||||
// Wait for first request
|
|
||||||
{
|
|
||||||
std::unique_lock lock{queue_mutex};
|
|
||||||
condition.wait(lock, [this] { return stop || !requests.empty(); });
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!stop) {
|
while (!stop) {
|
||||||
UniqueFunction<void> task;
|
UniqueFunction<void> task;
|
||||||
{
|
{
|
||||||
|
@ -27,7 +20,7 @@ ThreadWorker::ThreadWorker(std::size_t num_workers, const std::string& name) {
|
||||||
wait_condition.notify_all();
|
wait_condition.notify_all();
|
||||||
}
|
}
|
||||||
condition.wait(lock, [this] { return stop || !requests.empty(); });
|
condition.wait(lock, [this] { return stop || !requests.empty(); });
|
||||||
if (stop || requests.empty()) {
|
if (stop) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
task = std::move(requests.front());
|
task = std::move(requests.front());
|
||||||
|
|
Loading…
Reference in a new issue