sick_visionary_cpp_shared
3pp
boost
smart_ptr
detail
spinlock_std_atomic.hpp
Go to the documentation of this file.
1
#ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED
2
#define BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED
3
4
// MS compatible compilers support #pragma once
5
6
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
7
# pragma once
8
#endif
9
10
//
11
// Copyright (c) 2014 Peter Dimov
12
//
13
// Distributed under the Boost Software License, Version 1.0.
14
// See accompanying file LICENSE_1_0.txt or copy at
15
// http://www.boost.org/LICENSE_1_0.txt)
16
//
17
18
#include <
boost/smart_ptr/detail/yield_k.hpp
>
19
#include <atomic>
20
21
namespace
boost
22
{
23
24
namespace
detail
25
{
26
27
class
spinlock
28
{
29
public
:
30
31
std::atomic_flag
v_
;
32
33
public
:
34
35
bool
try_lock
()
36
{
37
return
!
v_
.test_and_set( std::memory_order_acquire );
38
}
39
40
void
lock
()
41
{
42
for
(
unsigned
k = 0; !
try_lock
(); ++k )
43
{
44
boost::detail::yield
( k );
45
}
46
}
47
48
void
unlock
()
49
{
50
v_
.clear( std::memory_order_release );
51
}
52
53
public
:
54
55
class
scoped_lock
56
{
57
private
:
58
59
spinlock
&
sp_
;
60
61
scoped_lock
(
scoped_lock
const
& );
62
scoped_lock
&
operator=
(
scoped_lock
const
& );
63
64
public
:
65
66
explicit
scoped_lock
(
spinlock
& sp ):
sp_
( sp )
67
{
68
sp.lock();
69
}
70
71
~scoped_lock
()
72
{
73
sp_
.
unlock
();
74
}
75
};
76
};
77
78
}
// namespace detail
79
}
// namespace boost
80
81
#define BOOST_DETAIL_SPINLOCK_INIT { ATOMIC_FLAG_INIT }
82
83
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED
boost::detail::spinlock::lock
void lock()
Definition:
spinlock_std_atomic.hpp:40
boost::detail::spinlock::v_
int v_
Definition:
spinlock_gcc_arm.hpp:40
boost::detail::spinlock
Definition:
spinlock_gcc_arm.hpp:36
boost::detail::spinlock::try_lock
bool try_lock()
Definition:
spinlock_std_atomic.hpp:35
boost
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
boost::detail::spinlock::scoped_lock::scoped_lock
scoped_lock(spinlock &sp)
Definition:
spinlock_std_atomic.hpp:66
boost::detail::spinlock::scoped_lock::operator=
scoped_lock & operator=(scoped_lock const &)
boost::detail::spinlock::v_
std::atomic_flag v_
Definition:
spinlock_std_atomic.hpp:31
boost::detail::spinlock::scoped_lock::sp_
spinlock & sp_
Definition:
spinlock_gcc_arm.hpp:94
boost::detail::yield
void yield(unsigned)
Definition:
yield_k.hpp:167
boost::detail::spinlock::scoped_lock::scoped_lock
scoped_lock(scoped_lock const &)
boost::detail::spinlock::scoped_lock::~scoped_lock
~scoped_lock()
Definition:
spinlock_std_atomic.hpp:71
yield_k.hpp
boost::detail::spinlock::unlock
void unlock()
Definition:
spinlock_std_atomic.hpp:48
sick_visionary_ros
Author(s): SICK AG TechSupport 3D Snapshot
autogenerated on Thu Feb 8 2024 03:48:40