Logo ROOT  
Reference Guide
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} // namespace Internal
44} // namespace ROOT
45
46#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).
Definition: RSlotStack.hxx:30
ROOT::TSpinMutex fMutex
Definition: RSlotStack.hxx:34
const unsigned int fSize
Definition: RSlotStack.hxx:32
std::stack< unsigned int > fStack
Definition: RSlotStack.hxx:33
void ReturnSlot(unsigned int slotNumber)
Definition: RSlotStack.cxx:23
A spin mutex class which respects the STL interface for mutexes.
Definition: TSpinMutex.hxx:42
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.