From 38290dacd8faab166774d757a1e09807e57e9ba5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 13 Feb 2017 09:26:11 +0200 Subject: Add scheduler::shard_size() helper function --- build2/scheduler | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'build2/scheduler') 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; @@ -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_queue_; // Task queue. -- cgit v1.1