Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions
ScopedLock< Lockable > Class Template Reference

RAII-style mechanism for owning a lock of Lockable object for the duration of a scoped block. More...

#include <ScopedLock.h>

Inheritance diagram for ScopedLock< Lockable >:
NonCopyable< ScopedLock< Lockable > >

Public Member Functions

 ScopedLock (Lockable &lockable)
 Locks given lockable object. More...
 

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
LockableThe 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 62 of file ScopedLock.h.

Constructor & Destructor Documentation

ScopedLock ( Lockable &  lockable)

Locks given lockable object.

Parameters
lockablereference to the instance of Lockable object
Note
lockable object should outlive the ScopedLock object

Definition at line 69 of file ScopedLock.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.