YARP
Yet Another Robot Platform
LockGuard.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_OS_LOCKGUARD_H
7#define YARP_OS_LOCKGUARD_H
8
9#include <yarp/conf/system.h>
10
11#if !defined(YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE)
12YARP_COMPILER_WARNING("<yarp/os/LockGuard.h> file is deprecated")
13#endif
14
15#ifndef YARP_NO_DEPRECATED // since YARP 3.3
16
17#include <yarp/os/api.h>
18#include <mutex>
19
20namespace yarp::os {
21
22class Mutex;
23class RecursiveMutex;
24
35template <typename Lockable>
36class YARP_DEPRECATED_MSG("Use std::lock_guard or std::scoped_lock instead") AbstractLockGuard
37{
38public:
44 explicit AbstractLockGuard(Lockable& _lock);
45
50
51private:
54
56 AbstractLockGuard& operator=(const AbstractLockGuard&);
57
58 Lockable& lock;
59};
60
61// Implementation
62
65
66template <typename Lockable>
68 lock(_lock)
69{
70 lock.lock();
71}
72
73template <typename Lockable>
75{
76 lock.unlock();
77}
78
79template <typename Lockable>
81 lock(lg.lock)
82{
83}
84
85template <typename Lockable>
87{
88 return *this;
89}
90
91YARP_DEPRECATED_TYPEDEF_MSG("use std::lock_guard or std::scoped_lock instead") AbstractLockGuard<Mutex> LockGuard;
93
95
96} // namespace yarp::os
97
98#endif // YARP_NO_DEPRECATED
99
100#endif // YARP_OS_LOCKGUARD_H
This class is a mutex wrapper that provides a convenient RAII-style mechanism for owning a mutex for ...
Definition: LockGuard.h:37
~AbstractLockGuard()
destructs the LockGuard object, unlocks the underlying mutex
Definition: LockGuard.h:74
AbstractLockGuard(Lockable &_lock)
Acquires ownership of the given mutex _mutex.
Definition: LockGuard.h:67
Basic wrapper for mutual exclusion.
Definition: Mutex.h:31
RecursiveMutex offers exclusive, recursive ownership semantics:
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2895
STL namespace.
An interface to the operating system, including Port based communication.
#define YARP_WARNING_POP
Ends a temporary alteration of the enabled warnings.
Definition: system.h:334
#define YARP_COMPILER_WARNING(x)
Generate a warning at build time on supported compilers.
Definition: system.h:111
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition: system.h:333
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition: system.h:335
#define YARP_DEPRECATED_TYPEDEF_MSG(x)
Definition: api.h:99