Logo ROOT  
Reference Guide
 
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 <ROOT/TSpinMutex.hxx>
15
16#include <stack>
17
18namespace ROOT {
19namespace Internal {
20
21/// A thread-safe stack of N indexes (0 to size - 1).
22/// RSlotStack can be used to safely assign a "processing slot" number to
23/// each thread in multi-thread applications.
24/// In release builds, pop and push operations are unchecked, potentially
25/// resulting in undefined behavior if more slot numbers than available are
26/// requested.
27/// An important design assumption is that a slot will almost always be available
28/// when a thread asks for it, and if it is not available it will be very soon,
29/// therefore a spinlock is used for synchronization.
31private:
32 const unsigned int fSize;
33 std::stack<unsigned int> fStack;
35
36public:
37 RSlotStack() = delete;
38 RSlotStack(unsigned int size);
39 void ReturnSlot(unsigned int slotNumber);
40 unsigned int GetSlot();
41};
42
43/// A RAII object to pop and push slot numbers from a RSlotStack object.
44/// After construction the slot number is available as the data member fSlot.
47 unsigned int fSlot;
48 RSlotStackRAII(ROOT::Internal::RSlotStack &slotStack) : fSlotStack(slotStack), fSlot(slotStack.GetSlot()) {}
50};
51
52} // namespace Internal
53} // namespace ROOT
54
55#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
A thread-safe stack of N indexes (0 to size - 1).
ROOT::TSpinMutex fMutex
const unsigned int fSize
std::stack< unsigned int > fStack
void ReturnSlot(unsigned int slotNumber)
A spin mutex class which respects the STL interface for mutexes.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
A RAII object to pop and push slot numbers from a RSlotStack object.
ROOT::Internal::RSlotStack & fSlotStack
RSlotStackRAII(ROOT::Internal::RSlotStack &slotStack)