include
fkie_message_filters
helpers
scoped_unlock.h
Go to the documentation of this file.
1
/****************************************************************************
2
*
3
* fkie_message_filters
4
* Copyright © 2018-2020 Fraunhofer FKIE
5
* Author: Timo Röhling
6
*
7
* Licensed under the Apache License, Version 2.0 (the "License");
8
* you may not use this file except in compliance with the License.
9
* You may obtain a copy of the License at
10
*
11
* http://www.apache.org/licenses/LICENSE-2.0
12
*
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
18
*
19
****************************************************************************/
20
21
#ifndef INCLUDE_FKIE_MESSAGE_FILTERS_HELPERS_SCOPED_UNLOCK_H_
22
#define INCLUDE_FKIE_MESSAGE_FILTERS_HELPERS_SCOPED_UNLOCK_H_
23
24
namespace
fkie_message_filters
25
{
26
namespace
helpers
27
{
28
29
template
<
class
BasicLockable>
30
class
ScopedUnlock
31
{
32
public
:
33
ScopedUnlock
(BasicLockable& lockable)
34
:
lockable_
(lockable),
owns_lock_
(
lockable_
.owns_lock())
35
{
36
if
(
owns_lock_
)
lockable_
.unlock();
37
}
38
39
ScopedUnlock
(
ScopedUnlock
&& other) noexcept
40
:
lockable_
(other.lockable_),
owns_lock_
(other.owns_lock_)
41
{
42
other.owns_lock_ =
false
;
43
}
44
45
~ScopedUnlock
()
46
{
47
if
(
owns_lock_
)
lockable_
.lock();
48
}
49
50
ScopedUnlock
(
const
ScopedUnlock
&) =
delete
;
51
ScopedUnlock
&
operator=
(
const
ScopedUnlock
&) =
delete
;
52
53
private
:
54
BasicLockable&
lockable_
;
55
bool
owns_lock_
;
56
};
57
58
template
<
class
BasicLockable>
59
ScopedUnlock<BasicLockable>
with_scoped_unlock
(BasicLockable& lockable)
60
{
61
return
ScopedUnlock<BasicLockable>(lockable);
62
}
63
64
}
// namespace helpers
65
}
// namespace fkie_message_filters
66
67
#endif
/* INCLUDE_FKIE_MESSAGE_FILTERS_HELPERS_SCOPED_UNLOCK_H_ */
fkie_message_filters
Definition:
buffer.h:33
fkie_message_filters::helpers::ScopedUnlock::~ScopedUnlock
~ScopedUnlock()
Definition:
scoped_unlock.h:99
fkie_message_filters::helpers::ScopedUnlock::ScopedUnlock
ScopedUnlock(BasicLockable &lockable)
Definition:
scoped_unlock.h:87
fkie_message_filters::helpers::ScopedUnlock::owns_lock_
bool owns_lock_
Definition:
scoped_unlock.h:109
fkie_message_filters::helpers::ScopedUnlock::lockable_
BasicLockable & lockable_
Definition:
scoped_unlock.h:108
fkie_message_filters::helpers::ScopedUnlock::operator=
ScopedUnlock & operator=(const ScopedUnlock &)=delete
fkie_message_filters::helpers::with_scoped_unlock
ScopedUnlock< BasicLockable > with_scoped_unlock(BasicLockable &lockable)
Definition:
scoped_unlock.h:95
fkie_message_filters
Author(s): Timo Röhling
autogenerated on Wed Mar 2 2022 00:18:57