Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSpinLockGuard.h
Go to the documentation of this file.
1// @(#)root/meta:$Id$
2// Author: Rene Brun 07/01/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TSpinLockGuard
13#define ROOT_TSpinLockGuard
14
15#include <atomic>
16
17namespace ROOT {
18namespace Internal {
19
20/**
21* \class ROOT::Internal::TSpinLockGuard
22* \brief A spin mutex-as-code-guard class.
23* \ingroup Foundation
24* This class allows to acquire spin locks in combination with a std::atomic_flag variable.
25* For example:
26* ~~~{.cpp}
27* mutable std::atomic_flag fSpinLock;
28* [...]
29* ROOT::Internal::TSpinLockGuard slg(fSpinLock);
30* // do something important
31* [...]
32* ~~~{.cpp}
33*/
34
36 // Trivial spin lock guard
37public:
38 TSpinLockGuard(std::atomic_flag& aflag) : fAFlag(aflag)
39 {
40 while (fAFlag.test_and_set(std::memory_order_acquire));
41 }
43 fAFlag.clear(std::memory_order_release);
44 }
45
46private:
47 std::atomic_flag& fAFlag;
48};
49
50} // namespace Internal
51} // namespace ROOT
52
53#endif // ROOT_TSpinLockGuard
A spin mutex-as-code-guard class.
TSpinLockGuard(std::atomic_flag &aflag)
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.