Lumiera  0.pre.03
»edit your freedom«
work-force.cpp
Go to the documentation of this file.
1 /*
2  WorkForce.hpp - actively coordinated pool of workers for rendering
3 
4  Copyright (C) Lumiera.org
5  2023, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
32 #include "lib/util.hpp"
33 
34 
35 namespace vault{
36 namespace gear {
37 
38  namespace { // internal details
39 
40  size_t MINIMAL_CONCURRENCY = 2;
41 
42  } // internal details
43 
44 
45 
54  size_t work::Config::COMPUTATION_CAPACITY = Config::getDefaultComputationCapacity();
55 
59  size_t
61  {
62  return util::max (std::thread::hardware_concurrency()
63  , MINIMAL_CONCURRENCY);
64  }
65 
66 
74  void
75  work::performRandomisedSpin (size_t stepping, size_t randFact)
76  {
77  size_t degree = CONTEND_SOFT_FACTOR * (1+randFact) * stepping;
78  for (volatile size_t i=0; i<degree; ++i) {/*SPIN*/}
79  }
80 
90  microseconds
91  work::steppedRandDelay (size_t stepping, size_t randFact)
92  {
93  REQUIRE (stepping > 0);
94  uint factor = 1u << (stepping-1);
95  return (CONTEND_WAIT + 10us*randFact) * factor;
96  }
97 
98 
99 }} // namespace vault::gear
const microseconds CONTEND_WAIT
base time unit for the exponentially stepped-up sleep delay in case of contention ...
Definition: work-force.hpp:90
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
const size_t CONTEND_SOFT_FACTOR
base counter for a spinning wait loop
Definition: work-force.hpp:88
A pool of workers for multithreaded rendering.
static size_t COMPUTATION_CAPACITY
Nominal »full size« of a pool of concurrent workers.
Definition: work-force.hpp:115
Vault-Layer implementation namespace root.
static size_t getDefaultComputationCapacity()
default value for full computing capacity is to use all (virtual) cores.
Definition: work-force.cpp:60