The Pedigree Project
0.1
|
#include <Buffer.h>
Classes | |
struct | MonitorTarget |
struct | Segment |
Public Member Functions | |
Buffer (size_t bufferSize) | |
size_t | write (const T *buffer, size_t count, bool block=true) |
size_t | read (T *buffer, size_t count, bool block=true) |
void | disableWrites () |
void | disableReads () |
bool | enableWrites () |
bool | enableReads () |
size_t | getDataSize () |
size_t | getSize () |
bool | canWrite (bool block) |
bool | canRead (bool block) |
void | wipe () |
void | monitor (Thread *pThread, Event *pEvent) |
void | monitor (Semaphore *pSemaphore) |
void | cullMonitorTargets (Thread *pThread) |
void | cullMonitorTargets (Semaphore *pSemaphore) |
void | cullMonitorTargets (Event *pEvent) |
Private Member Functions | |
WITHOUT_IMPLICIT_CONSTRUCTORS (Buffer) | |
void | notifyMonitors () |
void | addSegment (const T *buffer, size_t count) |
Private Attributes | |
size_t | m_BufferSize |
size_t | m_DataSize |
Mutex | m_Lock |
ConditionVariable | m_WriteCondition |
ConditionVariable | m_ReadCondition |
List< Segment * > | m_Segments |
List< MonitorTarget * > | m_MonitorTargets |
bool | m_bCanRead |
bool | m_bCanWrite |
Static Private Attributes | |
static const size_t | m_SegmentSize = 32768 |
Friends | |
class | UnixSocket |
Provides a buffer of a specific size and utility functions for integration with e.g. File or other kernel systems.
allowShortOperation defines the action to take on overflow. If true, the buffer's write() operation is permitted to return a size less than requested if the buffer would overflow. Otherwise, the implementation is required to block until bytes are present (unless blocking has been explicitly denied).
Note that an attempt to read when writing is disabled that would block will always return the number of bytes read so far (or zero if none yet). The same is true for an attempt to write when reading is disabled if that would block.
|
private |
Create a new segment with the given data.
Definition at line 592 of file Buffer.cc.
References Buffer< T, allowShortOperation >::Segment::data, and Buffer< T, allowShortOperation >::Segment::size.
bool Buffer< T, allowShortOperation >::canRead | ( | bool | block | ) |
Check if the buffer can be read from.
Definition at line 437 of file Buffer.cc.
Referenced by ConsolePhysicalFile::readBytewise(), PsAuxFile::select(), and Pipe::select().
bool Buffer< T, allowShortOperation >::canWrite | ( | bool | block | ) |
Check if the buffer can be written to.
Definition at line 409 of file Buffer.cc.
Referenced by PsAuxFile::select(), Pipe::select(), and ConsoleMasterFile::writeBytewise().
void Buffer< T, allowShortOperation >::disableReads | ( | ) |
Disable further reads from the buffer. This will wake up all writers waiting on reader.
Definition at line 368 of file Buffer.cc.
Referenced by Pipe::decreaseRefCount().
void Buffer< T, allowShortOperation >::disableWrites | ( | ) |
Disable further writes to the buffer. This will wake up all readers waiting on a writer.
Definition at line 358 of file Buffer.cc.
Referenced by Pipe::decreaseRefCount().
bool Buffer< T, allowShortOperation >::enableReads | ( | ) |
Enable reads from the buffer.
Definition at line 387 of file Buffer.cc.
Referenced by Pipe::isFifo().
bool Buffer< T, allowShortOperation >::enableWrites | ( | ) |
Enable writes to the buffer.
Definition at line 378 of file Buffer.cc.
Referenced by Pipe::isFifo().
size_t Buffer< T, allowShortOperation >::getDataSize | ( | ) |
size_t Buffer< T, allowShortOperation >::getSize | ( | ) |
|
private |
Helper function to send events upon completing an action.
Clears all monitors as a side effect.
Definition at line 568 of file Buffer.cc.
References Semaphore::release(), and Thread::sendEvent().
size_t Buffer< T, allowShortOperation >::read | ( | T * | buffer, |
size_t | count, | ||
bool | block = true |
||
) |
Read
count | values into |
buffer,optionally | blocking if no more values are available to be read yet. |
Definition at line 236 of file Buffer.cc.
References Buffer< T, allowShortOperation >::Segment::data, Buffer< T, allowShortOperation >::Segment::reader, and Buffer< T, allowShortOperation >::Segment::size.
Referenced by PsAuxFile::readBytewise(), Pipe::readBytewise(), ConsoleMasterFile::readBytewise(), ConsoleSlaveFile::readBytewise(), and ConsolePhysicalFile::readBytewise().
void Buffer< T, allowShortOperation >::wipe | ( | ) |
Wipes the buffer.
Definition at line 466 of file Buffer.cc.
Referenced by Pipe::isFifo().
size_t Buffer< T, allowShortOperation >::write | ( | const T * | buffer, |
size_t | count, | ||
bool | block = true |
||
) |
Write
count | values from |
buffer,optionally | blocking before writing if there is insufficient space. |
Definition at line 64 of file Buffer.cc.
References Buffer< T, allowShortOperation >::Segment::data, and Buffer< T, allowShortOperation >::Segment::size.
Referenced by PsAuxFile::select(), and Pipe::writeBytewise().
|
staticprivate |