21#ifndef SYNCHRONIZEDCONFIG_H
22#define SYNCHRONIZEDCONFIG_H
80 return parent->config[parent->indexAtomic.
load(
129 return config[updateIndex];
150 std::set<Reader*> readers;
159 return config[updateIndex];
167 Reader* lockingReaders = 0;
168 for (
typename std::set<Reader*>::iterator iter = readers.begin() ;
169 iter != readers.end() ;
172 if ((*iter)->prevLock) {
173 (*iter)->next = lockingReaders;
174 lockingReaders = *iter;
179 while (lockingReaders) {
181 Reader** prev = &lockingReaders;
182 for (
Reader* p = lockingReaders ; p ; p = p->next) {
192 return config[updateIndex];
200 parent(&config), lockCount(1), lock(0) {
201 parent->readers.insert(
this);
206 parent(config), lockCount(1), lock(0) {
207 parent->readers.insert(
this);
212 parent->readers.erase(
this);
267 this->syncer = syncer;
285 const T& operator *()
const {
return syncer->syncedData(); }
286 T& operator *() {
return syncer->syncedData(); }
288 const T* operator ->()
const {
return &syncer->syncedData(); }
289 T* operator ->() {
return &syncer->syncedData(); }
BackBuffer object to be accessed by multiple non-real-time threads.
virtual void endSync() OVERRIDE
Signal that the synchronized code block has been left.
virtual T & syncedData() OVERRIDE
Retrieve reference to critical, shared data.
virtual void beginSync() OVERRIDE
Signal intention to enter a synchronized code block.
const T & unsafeData() const
Synchronization / protection of data shared between multiple threads by using a double buffer design.
Sync< T > back()
Synchronized access of the shared data for multiple non-real-time threads.
const T & unsafeBack() const
Get the backbuffer data unprotected, that is without locking or any means of synchronizations.
Sync< T > front()
Synchronized access of the shared data for EXACTLY one real-time thread.
FrontBuffer object to be accessed by exactly ONE real-time thread.
virtual void endSync() OVERRIDE
Signal that the synchronized code block has been left.
FrontBuffer(BackBuffer< T > &backBuffer)
virtual T & syncedData() OVERRIDE
Retrieve reference to critical, shared data.
virtual void beginSync() OVERRIDE
Signal intention to enter a synchronized code block.
Wraps as a kind of pointer class some data object shared with other threads, to protect / synchronize...
Sync(Synchronizer< T > *syncer)
void Unlock()
Unlock the configuration object.
Reader(SynchronizedConfig &config)
T & Lock()
Gets the configuration object for use by the real time thread.
Thread-safe management of configuration data, where the data is updated by a single non real time thr...
T & GetConfigForUpdate()
Gets the configuration object for use by the non real time thread.
T & SwitchConfig()
Atomically switch the newly updated configuration object with the one used by the real time thread,...
const T & GetUnsafeUpdateConfig() const
Get the data on update side for read-only access.
Base interface class for classes that implement synchronization of data shared between multiple threa...
virtual void beginSync()=0
Signal intention to enter a synchronized code block.
virtual void endSync()=0
Signal that the synchronized code block has been left.
virtual T & syncedData()=0
Retrieve reference to critical, shared data.
int load(memory_order order=memory_order_seq_cst) const volatile
void store(int m, memory_order order=memory_order_seq_cst) volatile
Implementation of a small subset of the C++11 atomic operations.
void atomic_thread_fence(memory_order order)