aboutsummaryrefslogtreecommitdiff
path: root/build2/scheduler
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-02-13 09:26:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-02-13 12:42:42 +0200
commit38290dacd8faab166774d757a1e09807e57e9ba5 (patch)
treebff156e0bf4c906828800b35c32042f69a5ebd1b /build2/scheduler
parent62f962ec68435f6acade5769335153ffb90aad69 (diff)
Add scheduler::shard_size() helper function
Diffstat (limited to 'build2/scheduler')
-rw-r--r--build2/scheduler12
1 files changed, 11 insertions, 1 deletions
diff --git a/build2/scheduler b/build2/scheduler
index c487b88..430fdf2 100644
--- a/build2/scheduler
+++ b/build2/scheduler
@@ -241,6 +241,16 @@ namespace build2
return std::thread::hardware_concurrency ();
}
+ // Return a prime number that can be used as a lock shard size that's
+ // appropriate for the scheduler's concurrency. Use power of two values
+ // for mul for higher-contention shards and for div for lower-contention
+ // ones. Always return 1 for serial execution.
+ //
+ // Note: can only be called from threads that have observed startup.
+ //
+ size_t
+ shard_size (size_t mul = 1, size_t div = 1) const;
+
private:
using lock = std::unique_lock<std::mutex>;
@@ -352,7 +362,7 @@ namespace build2
bool shutdown = true;
};
- size_t wait_queue_size_; // Multiple of max_threads.
+ size_t wait_queue_size_; // Proportional to max_threads.
unique_ptr<wait_slot[]> wait_queue_;
// Task queue.