This is Unofficial EPICS BASE Doxygen Site
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
spinlock_sync.hpp
Go to the documentation of this file.
1
#ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_SYNC_HPP_INCLUDED
2
#define BOOST_SMART_PTR_DETAIL_SPINLOCK_SYNC_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) 2008 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
20
#if defined( __ia64__ ) && defined( __INTEL_COMPILER )
21
# include <ia64intrin.h>
22
#endif
23
24
namespace
boost
25
{
26
27
namespace
detail
28
{
29
30
class
spinlock
31
{
32
public
:
33
34
int
v_
;
35
36
public
:
37
38
bool
try_lock
()
39
{
40
int
r = __sync_lock_test_and_set( &v_, 1 );
41
return
r == 0;
42
}
43
44
void
lock
()
45
{
46
for
(
unsigned
k = 0; !
try_lock
(); ++k )
47
{
48
boost::detail::yield
( k );
49
}
50
}
51
52
void
unlock
()
53
{
54
__sync_lock_release( &v_ );
55
}
56
57
public
:
58
59
class
scoped_lock
60
{
61
private
:
62
63
spinlock
& sp_;
64
65
scoped_lock
(
scoped_lock
const
& );
66
scoped_lock
& operator=(
scoped_lock
const
& );
67
68
public
:
69
70
explicit
scoped_lock
(
spinlock
& sp ): sp_( sp )
71
{
72
sp.lock();
73
}
74
75
~scoped_lock
()
76
{
77
sp_.unlock();
78
}
79
};
80
};
81
82
}
// namespace detail
83
}
// namespace boost
84
85
#define BOOST_DETAIL_SPINLOCK_INIT {0}
86
87
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_SYNC_HPP_INCLUDED
boost
Definition:
assert.hpp:91
boost::detail::spinlock::lock
void lock()
Definition:
spinlock_sync.hpp:44
boost::detail::spinlock::try_lock
bool try_lock()
Definition:
spinlock_sync.hpp:38
boost::detail::spinlock::scoped_lock::scoped_lock
scoped_lock(spinlock &sp)
Definition:
spinlock_sync.hpp:70
boost::detail::yield
void yield(unsigned)
Definition:
yield_k.hpp:139
detail
Definition:
pvUnitTest.h:17
boost::detail::spinlock
Definition:
spinlock_pt.hpp:26
boost::detail::spinlock::scoped_lock
Definition:
spinlock_pt.hpp:51
boost::detail::spinlock::unlock
void unlock()
Definition:
spinlock_sync.hpp:52
boost::detail::spinlock::scoped_lock::~scoped_lock
~scoped_lock()
Definition:
spinlock_sync.hpp:75
yield_k.hpp
boost::detail::spinlock::v_
int v_
Definition:
spinlock_sync.hpp:34
modules
libcom
vxWorks
boost
smart_ptr
detail
spinlock_sync.hpp
Generated by
1.8.11