Skip to main content
Pigweed's logo Pigweed
  1. Home
  2. Reference
  3. C/C++
  4. pw_sync
  5. pw::ScopedLocker< BasicLockable > Class Template Reference
Loading...
Searching...
No Matches
pw::ScopedLocker< BasicLockable > Class Template Reference

Overview

template<typename BasicLockable>
class pw::ScopedLocker< BasicLockable >

RAII helper to use BasicLockable locks with thread safety lock annotations with more capabilities than std::lock_guard.

Note
The simpler std::lock_guard RAII helper is recommended by default due to additional member overhead. pw::ScopedLocker should only be used if more complex lock management is required where RAII alone is insufficient.

Unlike a std::lock_guard and std::scoped_lock, this helper can be constructed with the lock deferred. In addition, this does not support std::lock deadlock avoidance algorithm from std::scoped_lock.

Lastly this supports explicit lock() and unlock() like std::unique_lock, however unlike std::unique_lock, pw::ScopedLocker does not support the use of Lockables's conditional lock acquisition, try_lock(). This means that this supports thread safety lock annotations unlike std::unique_lock.

Public Member Functions

 ScopedLocker (BasicLockable &lock) noexcept
 
 ScopedLocker (BasicLockable &lock, std::adopt_lock_t) noexcept
 
 ScopedLocker (BasicLockable &lock, std::defer_lock_t) noexcept
 
 ScopedLocker (const ScopedLocker &)=delete
 
 ScopedLocker (ScopedLocker &&)=delete
 
ScopedLockeroperator= (const ScopedLocker &)=delete
 
ScopedLockeroperator= (ScopedLocker &&)=delete
 
void lock ()
 
void unlock ()
 

The documentation for this class was generated from the following file: