-
- Downloads
Add SCOPE_LOCK(mutex) macro
Add a macro SCOPE_LOCK(mutex) which locks the given mutex and unlocks it when the scope ends (this uses RAII, so the mutex will correctly get unlocked even when the scope is exited via return or exception). This does the same as C++11's std::lock_guard, but far less verbose: To use std::lock_guard with a mutex m, one nees to do something like std::lock_guard<mutex> guard(m); where the mutex's type needs to be repeated, and a name needs to be invented for the guard which will likely not be used again. This macro makes these things unnecessary, and one just writes SCOPE_LOCK(m); Note that WITH_LOCK(m) { ... } should usually be preferred over SCOPE_LOCK. However, SCOPE_LOCK can come in handy in some cases, for example adding a lock to a function without reindenting it. Signed-off-by:Nadav Har'El <nyh@cloudius-systems.com> Signed-off-by:
Pekka Enberg <penberg@cloudius-systems.com>
Loading
Please register or sign in to comment