Attention
This functionality is only available in the C++ toolkits. For other languages, we recommend using language-specific functionality instead.
OEProtectedBuffer¶
template<class BUFFER>
class OEProtectedBuffer
Thread-safe first-in-first-out (FIFO) queue that can have multiple
producers and consumers. Meant to wrap around either a
OEBoundedBuffer or
OEUnboundedBuffer object to provide thread-safe
access to those buffers. The OEBoundedBuffer
queue should be used to control memory consumption, as the
OEProtectedBuffer::Put
operation will block,
allowing the queue to empty first. The
OEUnboundedBuffer queue will continue to
consume memory with every
OEProtectedBuffer::Put
operation.
Constructors¶
OEProtectedBuffer(oesize_t maxsize)
OEProtectedBuffer(oesize_t maxsize, oesize_t threshold)
Constructs a new BUFFER
, passing maxsize
to the child
buffer implementation. The threshold
argument is a
performance tuning parameter that determines how often
OECondition::Broadcast
is
called. Broadcasting to other queue users too often can have
negative performance implications as threads can be woken when
there is not enough work in the queue to fill up their time
quantum. Too infrequently means threads are left idle too long
before being awoken with new to perform. The default
threshold
is half of maxsize
.
Null¶
value_type Null()
The value used to signal termination to the queue. Calling
OEProtectedBuffer::Put
with the value
returned by the Null
method signals that the queue is ‘done’
and should not accept anymore data. Subsequent
OEProtectedBuffer::Put
operations will fail
and return
false
. OEProtectedBuffer::Get
will
continue to return data until the queue is empty, and then start
returning the result of the Null
method as well. Note, this
method returns the default constructed value for the
value_type
being stored in the queue, this is typically
0
or NULL
for integral or pointer types respectively.
Peek¶
value_type Peek()
Returns the item that will be returned by the next call to
OEProtectedBuffer::Get
, but does not remove
it from the buffer.
Warning
The above is not guaranteed if there are multiple consumers,
i.e., other threads calling
OEProtectedBuffer::Get
interleaved with
the thread calling
OEProtectedBuffer::Peek
.