52 #ifndef SRC_VAULT_GEAR_WORK_FORCE_H_ 53 #define SRC_VAULT_GEAR_WORK_FORCE_H_ 75 using std::chrono::milliseconds;
76 using std::chrono::microseconds;
77 using std::chrono_literals::operator
""ms;
78 using std::chrono_literals::operator
""us;
79 using std::this_thread::sleep_for;
129 using Launch = lib::Thread::Launch;
142 : CONF{move (config)}
143 , thread_{Launch{&Worker::pullWork,
this}
149 std::atomic<bool> emergency{
false};
152 bool isDead()
const {
return not thread_; }
164 bool regularExit{
false};
170 if (emergency.load (std::memory_order_relaxed))
172 if (res == activity::KICK)
173 res = contentionWait();
177 if (res == activity::WAIT)
181 if (res != activity::PASS)
190 CONF::finalHook (not regularExit);
202 return activity::PASS;
205 return activity::HALT;
207 size_t idleCycles_{0};
217 for (uint i=0; i<kickLevel_; ++i)
220 std::this_thread::yield();
230 return activity::PASS;
232 size_t kickLevel_{0};
252 using Pool = std::list<work::Worker<CONF>>;
260 : setup_{move (config)}
282 size_t scale{setup_.COMPUTATION_CAPACITY};
284 for (uint i = workers_.size(); i < scale; ++i)
285 workers_.emplace_back (setup_);
289 incScale(uint step =+1)
291 uint i = workers_.size();
292 uint target = util::min (i+step, setup_.COMPUTATION_CAPACITY);
293 for ( ; i < target; ++i)
294 workers_.emplace_back (setup_);
300 for (
auto& w : workers_)
301 w.emergency.store (
true, std::memory_order_relaxed);
303 sleep_for (setup_.IDLE_WAIT);
309 unConst(workers_).remove_if([](
auto& w){
return w.isDead(); });
310 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.