pc_stack
|
 |
An os_pc_stack is a
last-in-first-out (LIFO) based producer consumer stack with a specified maximum
size (bounded buffer). Items can be inserted into the stack using the push()
method. If the stack is full, the calling thread blocks until the stack is not
full. Items can be removed from the stack in a LIFO order using the pop()
method. If the stack is empty, the calling thread blocks until the stack is not
empty.
The template arguments of the os_pc_stack
class are similar to the C++ standard library stack
container adapter class.
Declaration
#include <ospace/thread/pcstack.h>
template< class T, class Container >
class os_pc_stack
Interface
Constructor
os_pc_stack(
size_type max_size )
Constructs a stack with a maximum size limit of max_size
and a default constructed object of type Container
as the internal buffer.
Constructor
os_pc_stack(
size_type max_size ,
const Container& container )
Constructs a stack with a maximum size limit of max_size
and a copy of container as the internal buffer.
Destructor
~os_pc_priority_queue()
Destroys the stack.
<
bool
operator<( const os_pc_stack< T, Container >& other
) const
Returns true if this
stack is lexicographically less than other .
==
bool
operator==( const os_pc_stack< T, Container >& other
) const
Returns true if this
stack and other are equivalent.
close
void close()
Closes the stack. No items will be allowed to be
pushed into the stack. Items will be allowed to be popped until the stack
becomes empty.
closed
bool closed()
const
Returns true if closed
for adding new items. All threads calling pop()
will not block.
empty
bool empty()
const
Returns true if the
stack contain no elements.
full
bool full()
const
Returns true if the
stack is full.
max_size
size_type
max_size() const
Returns the maximum number of elements the stack
can contain.
pop
value_type
pop()
Removes the item in the front of the stack (LIFO
order) and returns it. If the stack is empty, the calling thread blocks
until the stack is not empty. If this method is called after the stack is
closed, then an exception is thrown.
Throws: os_thread_toolkit_error
pop
void pop(
value_type& value )
Removes the item in the front of the stack (LIFO
order) and places a copy of it in value . If the
stack is empty, the calling thread blocks until the stack is not empty. If
this method is called after the stack is closed, then an exception is
thrown.
Throws: os_thread_toolkit_error
pop
bool pop(
value_type& value ,
long milliseconds )
Removes the item in the front of the stack (LIFO
order) and places a copy of it in value . If the
stack is empty, the calling thread blocks until the stack is not empty or
until milliseconds time expires. Returns true
if the value is filled with the popped value. If
this method is called after the stack is closed, then an exception is
thrown.
Throws: os_thread_toolkit_error
push
void push(
const value_type& value )
Inserts the item value
into the stack. If the stack is full, the calling thread blocks until the
stack is not full. If this method is called after the stack is closed, then
an exception is thrown.
Throws: os_thread_toolkit_error
push
bool push(
const value_type& value ,
long milliseconds )
Inserts the item value
into the stack. If the stack is full, the calling thread blocks until the
stack is not full or until milliseconds time
expires. Returns true if the value
is inserted. If this method is called after the stack is closed, then an
exception is thrown.
Throws: os_thread_toolkit_error
reopen
void reopen()
Reopens the stack for pushing and popping items.
size
size_type
size() const
Returns the number of elements that the stack
currently contains.
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.