Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RSlotStack.cxx
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#include <ROOT/RSlotStack.hxx>
12
13#include <stdexcept>
14#include <string>
15
17
19{
20 if (slot >= fSlots.size())
21 throw std::invalid_argument("RSlotStack: A slot that is larger than the number of slots was returned :" +
22 std::to_string(slot));
23 bool expected = true;
24 if (!fSlots[slot].fAtomic.compare_exchange_strong(expected, false))
25 throw std::logic_error("RSlotStack: A slot that is not assigned was returned: " + std::to_string(slot));
26}
27
29{
30 while (true) {
31 for (unsigned int i = 0; i < fSlots.size(); ++i) {
32 // test if a slot is available (assigned == false)
33 bool expectedState = false;
34 if (fSlots[i].fAtomic.compare_exchange_strong(expectedState, true)) {
35 return i;
36 }
37 }
38 }
39}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
void ReturnSlot(unsigned int slotNumber)