43 #ifndef SRC_VAULT_GEAR_WORK_FORCE_H_ 44 #define SRC_VAULT_GEAR_WORK_FORCE_H_ 66 using std::chrono::milliseconds;
67 using std::chrono::microseconds;
68 using std::chrono_literals::operator
""ms;
69 using std::chrono_literals::operator
""us;
70 using std::this_thread::sleep_for;
120 using Launch = lib::Thread::Launch;
133 : CONF{move (config)}
134 , thread_{Launch{&Worker::pullWork,
this}
140 std::atomic<bool> emergency{
false};
143 bool isDead()
const {
return not thread_; }
155 bool regularExit{
false};
161 if (emergency.load (std::memory_order_relaxed))
163 if (res == activity::KICK)
164 res = contentionWait();
168 if (res == activity::WAIT)
172 if (res != activity::PASS)
181 CONF::finalHook (not regularExit);
193 return activity::PASS;
196 return activity::HALT;
198 size_t idleCycles_{0};
208 for (uint i=0; i<kickLevel_; ++i)
211 std::this_thread::yield();
221 return activity::PASS;
223 size_t kickLevel_{0};
243 using Pool = std::list<work::Worker<CONF>>;
251 : setup_{move (config)}
273 size_t scale{setup_.COMPUTATION_CAPACITY};
275 for (uint i = workers_.size(); i < scale; ++i)
276 workers_.emplace_back (setup_);
280 incScale(uint step =+1)
282 uint i = workers_.size();
283 uint target = util::min (i+step, setup_.COMPUTATION_CAPACITY);
284 for ( ; i < target; ++i)
285 workers_.emplace_back (setup_);
291 for (
auto& w : workers_)
292 w.emergency.store (
true, std::memory_order_relaxed);
294 sleep_for (setup_.IDLE_WAIT);
300 unConst(workers_).remove_if([](
auto& w){
return w.isDead(); });
301 return workers_.size();
const size_t CONTEND_SOFT_LIMIT
zone for soft anti-contention measures, counting continued contention events
Individual worker thread: repeatedly pulls the doWork functor.
#define ERROR_LOG_AND_IGNORE(_FLAG_, _OP_DESCR_)
convenience shortcut for a sequence of catch blocks just logging and consuming an error...
#define ASSERT_MEMBER_FUNCTOR(_EXPR_, _SIG_)
Macro for a compile-time check to verify some member is present and comprises something invokable wit...
const microseconds CONTEND_WAIT
base time unit for the exponentially stepped-up sleep delay in case of contention ...
void(bool) SIG_FinalHook
config should define callable invoked at exit (argument: isFailure)
const size_t DISMISS_CYCLES
number of wait cycles before an idle worker terminates completely
Any copy and copy construction prohibited.
Primary class template for std::hash.
microseconds steppedRandDelay(size_t, size_t)
Calculate the delay time for a stronger anti-contention wait.
activity::Proc(void) SIG_WorkFun
config should define a callable with this signature to perform work
void performRandomisedSpin(size_t, size_t)
This is part of the weak level of anti-contention measures.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Metaprogramming tools for transforming functor types.
const auto IDLE_WAIT
sleep-recheck cycle for workers deemed idle
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
bool isDead() const
this Worker starts out active, but may terminate
Convenience front-end to simplify and codify basic thread handling.
const size_t CONTEND_STARK_LIMIT
zone for stark measures, performing a sleep with exponential stepping
const size_t CONTEND_SATURATION
upper limit for the contention event count
const size_t CONTEND_SOFT_FACTOR
base counter for a spinning wait loop
const milliseconds IDLE_WAIT
wait period when a worker falls idle
const size_t DISMISS_CYCLES
number of idle cycles after which the worker terminates
void activate(double degree=1.0)
Activate or scale up the worker pool.
Basic set of definitions and includes commonly used together (Vault).
A thin convenience wrapper to simplify thread-handling.
static size_t COMPUTATION_CAPACITY
Nominal »full size« of a pool of concurrent workers.
Proc
Result instruction from Activity activation.
Pool of worker threads for rendering.
const size_t CONTEND_RANDOM_STEP
stepping for randomisation of anti-contention measures
Base for configuration of the worker pool.
const double MAX_OVERPROVISIONING
safety guard to prevent catastrophic over-provisioning
Vault-Layer implementation namespace root.
static size_t getDefaultComputationCapacity()
default value for full computing capacity is to use all (virtual) cores.
Descriptor for a piece of operational logic performed by the scheduler.