Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
icl_core
src
icl_core_thread
SpinLock.h
Go to the documentation of this file.
1
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2
3
// -- BEGIN LICENSE BLOCK ----------------------------------------------
4
// This file is part of FZIs ic_workspace.
5
//
6
// This program is free software licensed under the LGPL
7
// (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8
// You can find a copy of this license in LICENSE folder in the top
9
// directory of the source code.
10
//
11
// © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12
//
13
// -- END LICENSE BLOCK ------------------------------------------------
14
15
//----------------------------------------------------------------------
22
//----------------------------------------------------------------------
23
#ifndef ICL_CORE_THREAD_SPIN_LOCK_H_INCLUDED
24
#define ICL_CORE_THREAD_SPIN_LOCK_H_INCLUDED
25
26
#include <boost/atomic.hpp>
27
28
namespace
icl_core
{
29
namespace
thread {
30
35
class
SpinLock
36
{
37
public
:
38
SpinLock
()
39
:
m_state
(
UNLOCKED
)
40
{ }
41
46
bool
lock
()
47
{
48
while
(
m_state
.exchange(
LOCKED
, boost::memory_order_acquire) ==
LOCKED
)
49
{
50
// busy-wait
51
}
52
return
true
;
53
}
54
60
bool
tryLock
()
61
{
62
return
(
m_state
.exchange(
LOCKED
, boost::memory_order_acquire) ==
LOCKED
);
63
}
64
66
void
unlock
()
67
{
68
m_state
.store(
UNLOCKED
, boost::memory_order_release);
69
}
70
71
private
:
73
enum
LockState
74
{
75
LOCKED
,
76
UNLOCKED
77
};
78
80
boost::atomic<LockState>
m_state
;
81
};
82
83
}
84
}
85
86
#endif
icl_core::thread::SpinLock::LockState
LockState
States of the lock.
Definition:
SpinLock.h:73
icl_core::thread::SpinLock::SpinLock
SpinLock()
Definition:
SpinLock.h:38
icl_core::thread::SpinLock::UNLOCKED
Definition:
SpinLock.h:76
icl_core::thread::SpinLock::lock
bool lock()
Definition:
SpinLock.h:46
icl_core::thread::SpinLock::LOCKED
Definition:
SpinLock.h:75
icl_core::thread::SpinLock::m_state
boost::atomic< LockState > m_state
Current lock state.
Definition:
SpinLock.h:80
icl_core::thread::SpinLock::unlock
void unlock()
Unlocks the mutex.
Definition:
SpinLock.h:66
icl_core
Definition:
Array2D.h:30
icl_core::thread::SpinLock::tryLock
bool tryLock()
Definition:
SpinLock.h:60
icl_core::thread::SpinLock
Definition:
SpinLock.h:35
fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58