YARP
Yet Another Robot Platform
LockGuard.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_OS_LOCKGUARD_H
10 #define YARP_OS_LOCKGUARD_H
11 
12 #include <yarp/os/api.h>
13 
14 namespace yarp {
15  namespace os {
16  template <typename Lockable>
18 
19 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
20  class Mutex;
22 #else
23  using Mutex = std::mutex;
24  using RecursiveMutex = std::recursive_mutex;
25 #endif
26 
29  }
30 }
31 
40 template <typename Lockable>
42 public:
48  explicit AbstractLockGuard(Lockable& _lock);
49 
54 
55 private:
56 
59 
62 
63  Lockable& lock;
64 };
65 
66 
67 //Implementation
68 template <typename Lockable>
70  : lock(_lock)
71 {
72  lock.lock();
73 }
74 
75 template <typename Lockable>
77 {
78  lock.unlock();
79 }
80 
81 template <typename Lockable>
83 : lock(lg.lock) { }
84 
85 template <typename Lockable>
87 
88 #endif // YARP_OS_LOCKGUARD_H
AbstractLockGuard< RecursiveMutex > RecursiveLockGuard
Definition: LockGuard.h:28
The main, catch-all namespace for YARP.
Definition: numeric.h:47
This class is a mutex wrapper that provides a convenient RAII-style mechanism for owning a mutex for ...
Definition: LockGuard.h:17
AbstractLockGuard< Mutex > LockGuard
Definition: LockGuard.h:21
~AbstractLockGuard()
destructs the LockGuard object, unlocks the underlying mutex
Definition: LockGuard.h:76
AbstractLockGuard & operator=(const AbstractLockGuard &)
Assignment operator is disabled.
Definition: LockGuard.h:86
AbstractLockGuard(Lockable &_lock)
Acquires ownership of the given mutex _mutex.
Definition: LockGuard.h:69
RecursiveMutex offers exclusive, recursive ownership semantics:
Lockable & lock
underlining mutex
Definition: LockGuard.h:63
Basic wrapper for mutual exclusion.
Definition: Mutex.h:28