template<typename T, typename LOCKTYPE>
class maxon::SynchronizedValue< T, LOCKTYPE >
A SynchronizedValue<T, LOCKTYPE> stores a value of type T, protected by a lock of type LOCKTYPE. Aliases exist for the common lock types, so SynchronizedValue should not be used directly. Instead, use Synchronized<T> (Spinlock), RWSynchronized<T> (ARWLock).
Access to the value is enabled through the Read() and Write() functions. If possible, prefer using Synchronized over manually pairing locks with values, because there's less room for mistakes.
- Template Parameters
-
T | Type of the contained value. |
LOCKTYPE | Type of the lock value. |
|
| SynchronizedValue ()=default |
|
| SynchronizedValue (const T &v) |
|
| SynchronizedValue (T &&v) |
|
template<typename ... ARGS> |
| SynchronizedValue (IN_PLACE_TYPE, ARGS &&... args) |
|
| SynchronizedValue (const typename std::conditional< TestForCopyFromMember< T >::isSupported, DummyParamType, SynchronizedValue >::type &src) |
|
| SynchronizedValue (SynchronizedValue &&src) |
|
SynchronizedValue & | operator= (const typename std::conditional< TestForCopyFromMember< T >::isSupported, DummyParamType, SynchronizedValue >::type &src) |
|
Result< void > | CopyFrom (const typename std::conditional< TestForCopyFromMember< T >::isSupported, SynchronizedValue, DummyParamType >::type &src) |
|
SynchronizedValue & | operator= (SynchronizedValue &&src) |
|
LockedWritePtr | Write () |
|
template<typename F > |
auto | Write (F &&func) -> decltype(func(_value)) |
|
template<typename U , typename F > |
auto | Write (U &other, F &&func) -> decltype(func(_value, _value)) |
|
template<typename F > |
auto | WriteAsync (F &&func) -> void |
|
LockedReadPtr | Read () const |
|
template<typename F > |
auto | Read (F &&func) const -> decltype(func(_value)) |
|
template<typename U , typename F > |
auto | Read (U &other, F &&func) -> decltype(func(_value, _value)) |
|
const T & | UnsynchronizedGet () const |
|
T & | UnsynchronizedGet () |
|
Returns a locked write pointer to the synchronized value. On creation, the respective lock is acquired. This may involve waiting, if the lock is already taken. During the lifetime of the pointer, the lock remains taken. The synchronized value can be accessed through the pointer. On destruction, the lock is released.
Example:
PyObject PyObject * v
Definition: abstract.h:297
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
Note that for each temporary pointer, the lock is acquired and released again. You may also store the locked pointer to chain multiple operations:
Synchronized<BaseArray<Int>>
v;
{
}
unsigned char * p
Definition: floatobject.h:87
#define MAXON_SCOPE
Definition: apibase.h:2898
#define iferr_return
Definition: resultbase.h:1521
This is equivalent to using ScopedLock
.
auto WriteAsync |
( |
F && |
func | ) |
-> void
|
Executes a given function that can safely modify the inner value, potentially in an asynchronous way. It 1. acquires the lock in some thread, 2. calls the function in that thread and passes a reference to the value as argument, 3. releases the lock. The function should have a signature equivalent to
Note that for locks (like Spinlock), WriteAsync will always be executed synchronously. However if you use a Serializer for LOCKTYPE, asynchronous execution may happen.
- Parameters
-
[in] | func | Function that gets asynchronous write access to the contained value. |