Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RSlotStack.hxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, Danilo Piparo CERN 03/2017
2
3/*************************************************************************
4 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_RSLOTSTACK
12#define ROOT_RSLOTSTACK
13
14#include <atomic>
15#include <vector>
16
17namespace ROOT {
18namespace Internal {
19
20/// A thread-safe list of N indexes (0 to size - 1).
21/// RSlotStack can be used to atomically assign a "processing slot" number to
22/// each thread in multi-threaded applications.
23/// When there are no more slots available, the thread busy-waits for a slot.
24/// This case should be avoided by the scheduler.
26 struct alignas(8) AtomicWrapper {
27 std::atomic_bool fAtomic{false};
28 AtomicWrapper() = default;
29 ~AtomicWrapper() = default;
30 AtomicWrapper(const AtomicWrapper &) = delete;
34 {
35 fAtomic = other.fAtomic.load();
36 return *this;
37 }
38 };
39 std::vector<AtomicWrapper> fSlots;
40
41public:
42 RSlotStack() = delete;
43 RSlotStack(unsigned int size);
44 void ReturnSlot(unsigned int slotNumber);
45 unsigned int GetSlot();
46};
47
48/// A RAII object to pop and push slot numbers from a RSlotStack object.
49/// After construction the slot number is available as the data member fSlot.
56
57} // namespace Internal
58} // namespace ROOT
59
60#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
A thread-safe list of N indexes (0 to size - 1).
std::vector< AtomicWrapper > fSlots
void ReturnSlot(unsigned int slotNumber)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
A RAII object to pop and push slot numbers from a RSlotStack object.
ROOT::Internal::RSlotStack & fSlotStack
RSlotStackRAII(ROOT::Internal::RSlotStack &slotStack)
AtomicWrapper & operator=(AtomicWrapper &&other)
AtomicWrapper(const AtomicWrapper &)=delete
AtomicWrapper & operator=(const AtomicWrapper &)=delete