aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/scheduler.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/scheduler.cxx')
-rw-r--r--libbuild2/scheduler.cxx34
1 files changed, 32 insertions, 2 deletions
diff --git a/libbuild2/scheduler.cxx b/libbuild2/scheduler.cxx
index c660bba..03842ec 100644
--- a/libbuild2/scheduler.cxx
+++ b/libbuild2/scheduler.cxx
@@ -144,8 +144,8 @@ namespace build2
if (collision)
stat_wait_collisions_++;
- // If we have spare active threads, then become active. Otherwise it
- // enters the ready queue.
+ // If we have spare active threads, then become active. Otherwise we enter
+ // the ready queue.
//
if (external)
external_--;
@@ -186,6 +186,36 @@ namespace build2
}
size_t scheduler::
+ allocate (size_t n)
+ {
+ if (max_active_ == 1) // Serial execution.
+ return 0;
+
+ lock l (mutex_);
+
+ if (active_ < max_active_)
+ {
+ size_t d (max_active_ - active_);
+ if (n == 0 || d < n)
+ n = d;
+ active_ -= n;
+ return n;
+ }
+ else
+ return 0;
+ }
+
+ void scheduler::
+ deallocate (size_t n)
+ {
+ if (max_active_ == 1) // Serial execution.
+ return;
+
+ lock l (mutex_);
+ active_ += n;
+ }
+
+ size_t scheduler::
suspend (size_t start_count, const atomic_count& task_count)
{
wait_slot& s (