Turi Create  4.0
turi::safe_circular_char_buffer Class Reference

#include <core/util/safe_circular_char_buffer.hpp>

Public Member Functions

void stop_reader ()
 
bool empty () const
 
std::streamsize size () const
 
std::streamsize free_space () const
 
std::streamsize reserved_size () const
 
std::streamsize write (const char *c, std::streamsize clen)
 
std::streamsize write_unsafe (const char *c, std::streamsize clen)
 
std::streamsize introspective_read (char *&s, std::streamsize clen)
 
std::streamsize blocking_introspective_read (char *&s, std::streamsize clen)
 
void begin_critical_section ()
 
void end_critical_section ()
 
void end_critical_section_with_signal ()
 

Detailed Description

A non-resizing circular char buffer with thread-safe write operations and a single reader

Definition at line 18 of file safe_circular_char_buffer.hpp.

Member Function Documentation

◆ begin_critical_section()

void turi::safe_circular_char_buffer::begin_critical_section ( )
inline

When begin critical section returns, it is guaranteed that no other writer will be touching the tail of the queue

Definition at line 105 of file safe_circular_char_buffer.hpp.

◆ blocking_introspective_read()

std::streamsize turi::safe_circular_char_buffer::blocking_introspective_read ( char *&  s,
std::streamsize  clen 
)

Same as introspective read. But blocks until there is something to read This function does not acquire a critical section.

◆ empty()

bool turi::safe_circular_char_buffer::empty ( ) const

Determine if the buffer is empty

◆ end_critical_section()

void turi::safe_circular_char_buffer::end_critical_section ( )
inline

Releases a critical section acquired by begin_critical_section

Definition at line 110 of file safe_circular_char_buffer.hpp.

◆ end_critical_section_with_signal()

void turi::safe_circular_char_buffer::end_critical_section_with_signal ( )
inline

Releases a critical section acquired by begin_critical_section, and signals the reader to begin reading if the reader is blocked

Definition at line 116 of file safe_circular_char_buffer.hpp.

◆ free_space()

std::streamsize turi::safe_circular_char_buffer::free_space ( ) const

Get the amount of free space reamining in the buffer

◆ introspective_read()

std::streamsize turi::safe_circular_char_buffer::introspective_read ( char *&  s,
std::streamsize  clen 
)

Returns a pointer (through s) and a length of the read. This pointer is a direct pointer into the internal buffer of this datastructure. The pointer is valid as long as no other operations are performed on this structure. The length of the introspective_read may be less than the number of bytes requested. Multiple calls to introspective_read may be necessary to read all data in the buffer. If the function returns 0, the buffer is empty.

No locks are acquired on this call.

◆ reserved_size()

std::streamsize turi::safe_circular_char_buffer::reserved_size ( ) const
inline

Gets the size of the buffer.

Note
: The useable space is reserved_size() - 1

Definition at line 54 of file safe_circular_char_buffer.hpp.

◆ size()

std::streamsize turi::safe_circular_char_buffer::size ( ) const

Get the total contents currently stored in the buffer.

◆ stop_reader()

void turi::safe_circular_char_buffer::stop_reader ( )

Stops the buffer and signals any blocking calls.

◆ write()

std::streamsize turi::safe_circular_char_buffer::write ( const char *  c,
std::streamsize  clen 
)

Returns 0 if the write doesn't fit

This function acquires the critical section to perform the write

◆ write_unsafe()

std::streamsize turi::safe_circular_char_buffer::write_unsafe ( const char *  c,
std::streamsize  clen 
)

Returns 0 if the write doesn't fit

This does the same as write(), but does not acquire the critical section. The caller should ensure safety


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