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;
133 : CONF{move (config)}
155 bool regularExit{
false};
161 if (
emergency.load (std::memory_order_relaxed))
181 CONF::finalHook (not regularExit);
192 sleep_for (CONF::IDLE_WAIT);
205 randFact_ = thisThreadHash() % CONTEND_RANDOM_STEP;
211 std::this_thread::yield();
243 using Pool = std::list<work::Worker<CONF>>;
273 size_t scale{
setup_.COMPUTATION_CAPACITY};
274 scale = size_t(
util::limited (0.0, degree*scale, scale*MAX_OVERPROVISIONING));
284 for ( ; i < target; ++i)
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(); });
Descriptor for a piece of operational logic performed by the scheduler.
A thin convenience wrapper to simplify thread-handling.
Any copy and copy construction prohibited.
Pool of worker threads for rendering.
void incScale(uint step=+1)
std::list< work::Worker< CONF > > Pool
void activate(double degree=1.0)
Activate or scale up the worker pool.
Individual worker thread: repeatedly pulls the doWork functor.
std::atomic< bool > emergency
emergency break to trigger cooperative halt
activity::Proc idleWait()
activity::Proc contentionWait()
bool isDead() const
this Worker starts out active, but may terminate
#define ERROR_LOG_AND_IGNORE(_FLAG_, _OP_DESCR_)
convenience shortcut for a sequence of catch blocks just logging and consuming an error.
Metaprogramming tools for detecting and transforming function types.
#define ASSERT_MEMBER_FUNCTOR(_EXPR_, _SIG_)
Macro for a compile-time check to verify some member is present and comprises something invokable wit...
constexpr NUM limited(NB lowerBound, NUM val, NB upperBound)
force a numeric to be within bounds, inclusively
OBJ * unConst(const OBJ *)
shortcut to save some typing when having to define const and non-const variants of member functions
Proc
Result instruction from Activity activation.
@ PASS
pass on the activation down the chain
@ KICK
back pressure; get out of the way but be back soon
@ WAIT
nothing to do; wait and re-check for work later
@ HALT
abandon this play / render process
const double MAX_OVERPROVISIONING
safety guard to prevent catastrophic over-provisioning
const microseconds CONTEND_WAIT
base time unit for the exponentially stepped-up sleep delay in case of contention
const size_t CONTEND_SATURATION
upper limit for the contention event count
const size_t CONTEND_SOFT_LIMIT
zone for soft anti-contention measures, counting continued contention events
const size_t CONTEND_STARK_LIMIT
zone for stark measures, performing a sleep with exponential stepping
const size_t CONTEND_RANDOM_STEP
stepping for randomisation of anti-contention measures
const size_t CONTEND_SOFT_FACTOR
base counter for a spinning wait loop
void(bool) SIG_FinalHook
config should define callable invoked at exit (argument: isFailure)
lib::Thread::Launch Launch
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.
microseconds steppedRandDelay(size_t, size_t)
Calculate the delay time for a stronger anti-contention wait.
Vault-Layer implementation namespace root.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Primary class template for std::hash.
Base for configuration of the worker pool.
static size_t getDefaultComputationCapacity()
default value for full computing capacity is to use all (virtual) cores.
static size_t COMPUTATION_CAPACITY
Nominal »full size« of a pool of concurrent workers.
const size_t DISMISS_CYCLES
number of idle cycles after which the worker terminates
const milliseconds IDLE_WAIT
wait period when a worker falls idle
Convenience front-end to simplify and codify basic thread handling.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Basic set of definitions and includes commonly used together (Vault).