The Pedigree Project 0.1
Public Member Functions | Private Types | List of all members
RingBuffer< T, preallocatedSize > Class Template Reference

#include <RingBuffer.h>

+ Inheritance diagram for RingBuffer< T, preallocatedSize >:
+ Collaboration diagram for RingBuffer< T, preallocatedSize >:

Public Member Functions

 RingBuffer (size_t ringSize)
 
uint64_t readableGeneration () const
 
uint64_t writableGeneration () const
 
bool monitor (Thread *pThread, Event *pEvent)
 monitor - add a new Event to be fired when something happens
 
bool monitor (Semaphore *pSemaphore)
 Add a Semaphore to be signaled when readiness changes or the ring closes.
 
void cullMonitorTargets (Thread *pThread)
 Cull all monitor targets pointing to pThread.
 
void cullMonitorTargets (Semaphore *pSemaphore)
 Cull all monitor targets pointing to pSemaphore.
 
void cullMonitorTargets (Event *pEvent)
 Cull all monitor targets pointing to pEvent.
 
- Public Member Functions inherited from Mailbox< T, preallocatedSize, Notifications >
 Mailbox (size_t ringSize)
 
 ~Mailbox ()
 Destructor - closes the ring and drains every admitted operation.
 
void close ()
 
MUST_USE_RESULT bool takeAfterClose (T &out)
 
Error write (const T &obj, Time::Timestamp &timeout)
 Writes one object, waiting for space up to the supplied timeout.
 
Error write (const T &obj)
 
bool closeWritesWithFinal (const T &obj)
 
Error tryWrite (const T &obj)
 
size_t write (const T *obj, size_t n, Time::Timestamp &timeout)
 Publishes each available chunk before waiting for more space.
 
size_t write (const T *obj, size_t n)
 
MUST_USE_RESULT bool read (T &out, Time::Timestamp &timeout, Error &error)
 
MUST_USE_RESULT bool read (T &out, Error &error)
 
size_t read (T *out, size_t n, Time::Timestamp &timeout)
 Removes each available chunk before waiting for more data.
 
size_t read (T *out, size_t n)
 
bool dataReady ()
 dataReady - is data ready for reading from the ring buffer?
 
bool canWrite ()
 canWrite - is it possible to write to the ring buffer without blocking?
 
MUST_USE_RESULT bool waitFor (MailboxWait::WaitType wait, Time::Timestamp &timeout, Error &error)
 waitFor - block until the given condition is true (readable/writeable)
 
bool waitFor (MailboxWait::WaitType wait, Time::Timestamp &timeout)
 
bool waitFor (MailboxWait::WaitType wait)
 

Private Types

using Base = Mailbox< T, preallocatedSize, RingBufferNotifications >
 

Additional Inherited Members

- Public Types inherited from Mailbox< T, preallocatedSize, Notifications >
enum  Error {
  NoError , Empty , WouldBlock , TimedOut ,
  Interrupted , ThreadTerminating , Closed
}
 
- Protected Member Functions inherited from Mailbox< T, preallocatedSize, Notifications >
bool readsClosed () const
 
- Protected Attributes inherited from Mailbox< T, preallocatedSize, Notifications >
RingQueue< T, preallocatedSize > m_Ring
 
Notifications m_Notifications
 
bool m_Closing = false
 
bool m_WriteClosed = false
 
bool m_FinalPending = false
 

Detailed Description

template<class T, size_t preallocatedSize = 0>
class RingBuffer< T, preallocatedSize >

Blocking queue with one-shot readiness subscriptions and edge generations.

Definition at line 53 of file RingBuffer.h.

Member Typedef Documentation

◆ Base

template<class T , size_t preallocatedSize = 0>
using RingBuffer< T, preallocatedSize >::Base = Mailbox<T, preallocatedSize, RingBufferNotifications>
private

Definition at line 54 of file RingBuffer.h.

Constructor & Destructor Documentation

◆ RingBuffer()

template<class T , size_t preallocatedSize = 0>
RingBuffer< T, preallocatedSize >::RingBuffer ( size_t  ringSize)
inlineexplicit

Definition at line 57 of file RingBuffer.h.

Member Function Documentation

◆ cullMonitorTargets() [1/3]

template<class T , size_t preallocatedSize = 0>
void RingBuffer< T, preallocatedSize >::cullMonitorTargets ( Event *  pEvent)
inline

Cull all monitor targets pointing to pEvent.

Definition at line 147 of file RingBuffer.h.

◆ cullMonitorTargets() [2/3]

template<class T , size_t preallocatedSize = 0>
void RingBuffer< T, preallocatedSize >::cullMonitorTargets ( Semaphore *  pSemaphore)
inline

Cull all monitor targets pointing to pSemaphore.

Definition at line 137 of file RingBuffer.h.

◆ cullMonitorTargets() [3/3]

template<class T , size_t preallocatedSize = 0>
void RingBuffer< T, preallocatedSize >::cullMonitorTargets ( Thread *  pThread)
inline

Cull all monitor targets pointing to pThread.

Definition at line 127 of file RingBuffer.h.

◆ monitor() [1/2]

template<class T , size_t preallocatedSize = 0>
bool RingBuffer< T, preallocatedSize >::monitor ( Semaphore *  pSemaphore)
inline

Add a Semaphore to be signaled when readiness changes or the ring closes.

Definition at line 106 of file RingBuffer.h.

References EMIT_IF, and Semaphore::release().

◆ monitor() [2/2]

template<class T , size_t preallocatedSize = 0>
bool RingBuffer< T, preallocatedSize >::monitor ( Thread *  pThread,
Event *  pEvent 
)
inline

monitor - add a new Event to be fired when something happens

This could be a read or a write event; after receiving the event be sure to call dataReady() and/or canWrite() to determine the state of the buffer.

Do not assume that an event means both a read and write will not block. In fact, never assume an event means either will not block. You may need to re-subscribe to the event if something else reads or writes to the ring buffer between the event trigger and your handling.

Definition at line 80 of file RingBuffer.h.

References EMIT_IF, Thread::sendEvent(), and Event::tryAcquireRegistration().

◆ readableGeneration()

template<class T , size_t preallocatedSize = 0>
uint64_t RingBuffer< T, preallocatedSize >::readableGeneration ( ) const
inline

Definition at line 59 of file RingBuffer.h.

◆ writableGeneration()

template<class T , size_t preallocatedSize = 0>
uint64_t RingBuffer< T, preallocatedSize >::writableGeneration ( ) const
inline

Definition at line 63 of file RingBuffer.h.


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