You.i Engine
CYILocklessCache< YI_CACHE_TYPE > Class Template Reference

Detailed Description

template<typename YI_CACHE_TYPE>
class CYILocklessCache< YI_CACHE_TYPE >

Lockless cache is a triple-buffered cache.

The indent is to be used between one or more reader threads, and a single writer thread. The reader thread(s) will always call Read(), and the writer thread will always call Write.

This class is partially thread-safe. It was made this way in order to be lockless. Do not attempt to have more than one writer thread calling the Write method.

#include <thread/YiLocklessCache.h>

Public Member Functions

 CYILocklessCache ()
bool HasNextRead () const
const YI_CACHE_TYPE & Read () const
void Write (const YI_CACHE_TYPE &rData)

Constructor & Destructor Documentation

◆ CYILocklessCache()

template<typename YI_CACHE_TYPE >
CYILocklessCache< YI_CACHE_TYPE >::CYILocklessCache ( )

Constructs a Lockless cache that can be read by one or more threads, but written by a single thread.

Member Function Documentation

◆ HasNextRead()

template<typename YI_CACHE_TYPE >
bool CYILocklessCache< YI_CACHE_TYPE >::HasNextRead ( ) const

Checks if there the cache has changed.

Convenient function to query wetter we have a cache that is different than what was returned by the previous Read() call. This function is thread-safe and lockless.

◆ Read()

template<typename YI_CACHE_TYPE >
const YI_CACHE_TYPE& CYILocklessCache< YI_CACHE_TYPE >::Read ( ) const

Reads the data currently stored and available within the cache. This function is thread-safe and lockless.

◆ Write()

template<typename YI_CACHE_TYPE >
void CYILocklessCache< YI_CACHE_TYPE >::Write ( const YI_CACHE_TYPE &  rData)

Writes the data into the cache.

If a reader thread is already reading the cache, the writer will write data in an unused buffer so the read thread is never affected and everything remains lockless.

This function is not thread-safe. Make sure only one thread calls this function.

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