Rebel Fork Framework
Urho3D::ThreadSafeCache< T > Class Template Reference

#include <Urho3D/Core/ThreadSafeCache.h>

Public Member Functions

void Invalidate ()
 Invalidate cached object.
 
bool IsInvalidated () const
 Return whether the object is invalid and has to be restored.
 
void Restore (const T &object)
 Restore cached object. This call may be ignored if cache is already restored.
 
ThreadSafeCache< T > & operator= (const T &object)
 Same as Restore.
 
const T & Get () const
 Return object value. Intentionally unchecked, caller must ensure that cache is valid.
 

Private Attributes

std::atomic_bool dirty_ = true
 Whether dirty flag is set.
 
SpinLockMutex mutex_
 Spinlock mutex for updating cached object.
 
object_ {}
 Cached object.
 

Detailed Description

template<class T>
class Urho3D::ThreadSafeCache< T >

Thread-safe cache that holds an object. It's safe to:

  • Invalidate cached object from multiple threads;
  • Restore cached object from multiple threads, as long as all threads assign the same value. It's unsafe to both invalidate and restore cached object from multiple threads simultaneously. If different threads assign different values on Restore, cache will keep first provided value.

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