Turi Create
4.0
|
#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 () |
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.
|
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.
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.
bool turi::safe_circular_char_buffer::empty | ( | ) | const |
Determine if the buffer is empty
|
inline |
Releases a critical section acquired by begin_critical_section
Definition at line 110 of file safe_circular_char_buffer.hpp.
|
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.
std::streamsize turi::safe_circular_char_buffer::free_space | ( | ) | const |
Get the amount of free space reamining in the buffer
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.
|
inline |
Gets the size of the buffer.
Definition at line 54 of file safe_circular_char_buffer.hpp.
std::streamsize turi::safe_circular_char_buffer::size | ( | ) | const |
Get the total contents currently stored in the buffer.
void turi::safe_circular_char_buffer::stop_reader | ( | ) |
Stops the buffer and signals any blocking calls.
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
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