mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Embed: (wiki syntax)

« Back to documentation index

ScopedLock< Lockable > Class Template Reference

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 > >, and NonCopyable< ScopedLock< Lockable > >.

Public Member Functions

 ScopedLock (Lockable &lockable)
 Locks given lockable object.
 ScopedLock (Lockable &lockable)
 Locks given lockable 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.
 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:
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 cmsis/BUILD/mbed/platform/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 cmsis/BUILD/mbed/platform/ScopedLock.h.

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 platform/ScopedLock.h.