Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
ScopedLock< Lockable > Class Template Reference
[ScopedLock functions]
RAII-style mechanism for owning a lock of Lockable object for the duration of a scoped block. More...
#include <ScopedLock.h>
Inherits NonCopyable< ScopedLock< Lockable > >.
Public Member Functions | |
ScopedLock (Lockable &lockable) | |
Locks given locable object. | |
Private Member Functions | |
MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &) | |
NonCopyable copy constructor. | |
MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator | |
NonCopyable copy assignment operator. |
Detailed Description
template<typename Lockable>
class mbed::ScopedLock< Lockable >
RAII-style mechanism for owning a lock of Lockable object for the duration of a scoped block.
- Template Parameters:
-
Lockable The type implementing BasicLockable concept
- Note:
- For type Lockable to be BasicLockable, the following conditions have to be satisfied:
- has public member function lock which blocks until a lock can be obtained for the current execution context
- has public member function unlock which releases the lock
Usage:
Example with rtos::Mutex
void foo(Mutex &m) { ScopedLock<Mutex> lock(m); // Mutex lock protects code in this block }
More generic example
template<typename Lockable> void foo(Lockable& lockable) { ScopedLock<Lockable> lock(lockable); // Code in this block runs under lock }
Definition at line 61 of file ScopedLock.h.
Constructor & Destructor Documentation
ScopedLock | ( | Lockable & | lockable ) |
Locks given locable object.
- Parameters:
-
lockable reference to the instance of Lockable object
- Note:
- lockable object should outlive the ScopedLock object
Definition at line 68 of file ScopedLock.h.
Generated on Tue Jul 12 2022 20:37:48 by
