Ardour
9.0-pre0-350-gf17a656217
spinlock.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License along
15
* with this program; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
*/
18
19
#ifndef _pbd_spinlock_h_
20
#define _pbd_spinlock_h_
21
22
#include <boost/smart_ptr/detail/spinlock.hpp>
23
#include <cstring>
24
25
#include "
pbd/libpbd_visibility.h
"
26
27
namespace
PBD
{
28
29
/* struct boost::detail::spinlock {
30
* void lock();
31
* bool try_lock();
32
* void unlock();
33
* };
34
*
35
* initialize with BOOST_DETAIL_SPINLOCK_INIT
36
*/
37
38
struct
spinlock_t
{
39
public
:
40
#ifdef BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED
41
/* C++11 non-static data member initialization,
42
* with non-copyable std::atomic ATOMIC_FLAG_INIT
43
*/
44
spinlock_t
() {}
45
#else
46
/* default C++ assign struct's first member */
47
spinlock_t
()
48
{
49
boost::detail::spinlock
init
= BOOST_DETAIL_SPINLOCK_INIT;
50
std::memcpy (&
l
, &
init
,
sizeof
(
init
));
51
}
52
#endif
53
void
lock
() {
l
.lock (); }
54
void
unlock
() {
l
.unlock (); }
55
bool
try_lock
() {
return
l
.try_lock (); }
56
57
private
:
58
#ifdef BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED
59
boost::detail::spinlock
l
= BOOST_DETAIL_SPINLOCK_INIT;
60
#else
61
boost::detail::spinlock
l
;
62
#endif
63
64
/* prevent copy construction */
65
spinlock_t
(
const
spinlock_t
&);
66
};
67
68
/* RAII wrapper */
69
class
LIBPBD_API
SpinLock
{
70
71
public
:
72
SpinLock
(
spinlock_t
&);
73
~SpinLock
();
74
75
private
:
76
spinlock_t
&
_lock
;
77
};
78
79
}
/* namespace */
80
81
#endif
/* _pbd_spinlock_h__ */
PBD::SpinLock
Definition:
spinlock.h:69
PBD::SpinLock::SpinLock
SpinLock(spinlock_t &)
PBD::SpinLock::_lock
spinlock_t & _lock
Definition:
spinlock.h:76
PBD::SpinLock::~SpinLock
~SpinLock()
libpbd_visibility.h
LIBPBD_API
#define LIBPBD_API
Definition:
libpbd_visibility.h:50
PBD
Definition:
axis_view.h:42
PBD::init
bool init()
PBD::spinlock_t
Definition:
spinlock.h:38
PBD::spinlock_t::spinlock_t
spinlock_t()
Definition:
spinlock.h:47
PBD::spinlock_t::lock
void lock()
Definition:
spinlock.h:53
PBD::spinlock_t::try_lock
bool try_lock()
Definition:
spinlock.h:55
PBD::spinlock_t::spinlock_t
spinlock_t(const spinlock_t &)
PBD::spinlock_t::l
boost::detail::spinlock l
Definition:
spinlock.h:61
PBD::spinlock_t::unlock
void unlock()
Definition:
spinlock.h:54
libs
pbd
pbd
spinlock.h
Generated on Tue Nov 5 2024 05:28:48 for Ardour by
1.9.1