Helper functions that should be passed to either a lock() or synchronized() invocation, these return implementation defined structs that will be used to lock the synchronized instance appropriately.
Declared in <folly/Synchronized.h>
template<
typename D,
typename M,
typename... Args>
auto
wlock(
Synchronized<D, M>& synchronized,
Args&&... args);
lock(wlock(one), rlock(two), wlock(three)); synchronized([]one, two) { ... }, wlock(one), rlock(two));
For example in the above rlock() produces an implementation defined read locking helper instance and wlock() a write locking helper
Subsequent arguments passed to these locking helpers, after the first, will be passed by const-ref to the corresponding function on the synchronized instance. This means that if the function accepts these parameters by value, they will be copied. Note that it is not necessary that the primary locking function will be invoked at all (for eg. the implementation might just invoke the try*Lock() method)
// Try to acquire the lock for one second synchronized( { ... }, wlock(one, 1s));
// The timed lock acquire might never actually be called, if it is not // needed by the underlying deadlock avoiding algorithm synchronized([]auto) { ... }, rlock(one), wlock(two, 1s));
Note that the arguments passed to to *lock() calls will be passed by const-ref to the function invocation, as the implementation might use them many times
A locking helper for use with lock() or synchronized().
| Name | Description |
|---|---|
| synchronized | The object to lock. |
| args | Extra arguments forwarded to the locking function. |