diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-02-10 07:56:33 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-02-13 12:42:42 +0200 |
commit | bcb2a89e111a918a48a132a2a29e0c26d724591d (patch) | |
tree | 282bd5358f32fa8983c81c0d746d7d05bd5c3ddf /build2/scheduler.txx | |
parent | 107357ca4d02341810f47dee20df034e9c4574e0 (diff) |
Redo scheduler task flag as atomic counter
Makes for simpler code and also seems to perform better.
Diffstat (limited to 'build2/scheduler.txx')
-rw-r--r-- | build2/scheduler.txx | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/build2/scheduler.txx b/build2/scheduler.txx index d5e9afa..f53c044 100644 --- a/build2/scheduler.txx +++ b/build2/scheduler.txx @@ -36,7 +36,7 @@ namespace build2 if ((td = push (*tq)) != nullptr) { - // Package the task. + // Package the task (under lock). // new (&td->data) task { &task_count, @@ -63,13 +63,16 @@ namespace build2 // task_count.fetch_add (1, std::memory_order_release); - lock l (mutex_); - task_ = true; - - // If there is a spare active thread, wake up (or create) the helper. + // If there is a spare active thread, wake up (or create) the helper + // (unless someone already snatched it). // - if (active_ < max_active_) - activate_helper (l); + if (queued_task_count_ != 0) + { + lock l (mutex_); + + if (active_ < max_active_) + activate_helper (l); + } return true; } |