YARP  2.3.68+220-20170323.2+git4955ef0
Yet Another Robot Platform
LockGuard.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 iCub Facility
3  * Authors: Francesco Romano
4  * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
5  */
6 
7 #ifndef YARP_OS_LOCKGUARD_H
8 #define YARP_OS_LOCKGUARD_H
9 
10 #include <yarp/os/api.h>
11 
12 namespace yarp {
13  namespace os {
14  template <typename Lockable>
16 
17  class Mutex;
19 
22  }
23 }
24 
33 template <typename Lockable>
35 public:
41  explicit AbstractLockGuard(Lockable& _lock);
42 
47 
48 private:
49 
52 
55 
56  Lockable& lock;
57 };
58 
59 
60 //Implementation
61 template <typename Lockable>
63  : lock(_lock)
64 {
65  lock.lock();
66 }
67 
68 template <typename Lockable>
70 {
71  lock.unlock();
72 }
73 
74 template <typename Lockable>
76 : lock(lg.lock) { }
77 
78 template <typename Lockable>
80 
81 #endif // YARP_OS_LOCKGUARD_H
AbstractLockGuard< RecursiveMutex > RecursiveLockGuard
Definition: LockGuard.h:21
The main, catch-all namespace for YARP.
This class is a mutex wrapper that provides a convenient RAII-style mechanism for owning a mutex for ...
Definition: LockGuard.h:15
AbstractLockGuard< Mutex > LockGuard
Definition: LockGuard.h:18
~AbstractLockGuard()
destructs the LockGuard object, unlocks the underlying mutex
Definition: LockGuard.h:69
AbstractLockGuard & operator=(const AbstractLockGuard &)
Assignment operator is disabled.
Definition: LockGuard.h:79
AbstractLockGuard(Lockable &_lock)
Acquires ownership of the given mutex _mutex.
Definition: LockGuard.h:62
RecursiveMutex offers exclusive, recursive ownership semantics:
Lockable & lock
underlining mutex
Definition: LockGuard.h:56
Basic wrapper for mutual exclusion.
Definition: Mutex.h:25