mCRL2
Loading...
Searching...
No Matches
spinlock.h
Go to the documentation of this file.
1// Author(s): Maurice Laveaux
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9
10#ifndef MCRL2_UTILITIES_SPINLOCK_H_
11#define MCRL2_UTILITIES_SPINLOCK_H_
12
13#include <atomic>
14
15namespace mcrl2
16{
17namespace utilities
18{
19
22{
23public:
24
26 void lock()
27 {
28 while (m_flag.test_and_set()) {};
29 }
30
33 bool try_lock()
34 {
35 return m_flag.test_and_set();
36 }
37
39 void unlock()
40 {
41 m_flag.clear();
42 }
43
44private:
45 std::atomic_flag m_flag;
46};
47
48} // namespace utilities.
49} // namespace mcrl2.
50
51#endif // MCRL2_UTILITIES_SPINLOCK_H_
Implements a very simple spinlock.
Definition spinlock.h:22
bool try_lock()
Tries to lock the spinlock, but also returns immediately.
Definition spinlock.h:33
std::atomic_flag m_flag
Definition spinlock.h:45
void lock()
Busy waits until the lock is unlocked.
Definition spinlock.h:26
void unlock()
Frees the lock.
Definition spinlock.h:39
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72