Loading...
Searching...
No Matches
vspace::Queue< T > Class Template Reference

`#include <vspace.h>`

## Data Structures

struct | Node

## Public Member Functions

| Queue (size_t bound=0)
void | enqueue (T item)
bool | try_enqueue (T item)
T | dequeue ()
Result< T > | try_dequeue ()

## Private Member Functions

VRef< Node > | pop ()
void | push (VRef< Node > node)
void | enqueue_nowait (T item)
T | dequeue_nowait ()

## Private Attributes

Semaphore | _incoming
Semaphore | _outgoing
bool | _bounded
FastLock | _lock
VRef< Node > | _head
VRef< Node > | _tail

## Friends

template<typename U>
class | EnqueueEvent
template<typename U>
class | DequeueEvent

## Detailed Description

template<typename T>
class vspace::Queue< T >

Definition at line 2380 of file vspace.h.

## Data Structure Documentation

## vspace::Queue::Node

struct vspace::Queue::Node

template<typename T>
struct vspace::Queue< T >::Node

Definition at line 2382 of file vspace.h.

Data Fields
T | data |
VRef< Node > | next |

## Constructor & Destructor Documentation

## Queue()

template<typename T>

vspace::Queue< T >::Queue | ( | size_t | bound = 0 | ) |

inline

Definition at line 2435 of file vspace.h.

:
_incoming(0),
_outgoing(bound),
_bounded(bound != 0),
_head(),
_tail(),
_lock() {
}
vspace::Queue
Definition vspace.h:2380
vspace::Queue::_incoming
Semaphore _incoming
Definition vspace.h:2386
vspace::Queue::_outgoing
Semaphore _outgoing
Definition vspace.h:2387
vspace::Queue::_bounded
bool _bounded
Definition vspace.h:2388
vspace::Queue::_head
VRef< Node > _head
Definition vspace.h:2390
vspace::Queue::_tail
VRef< Node > _tail
Definition vspace.h:2390
vspace::Queue::_lock
FastLock _lock
Definition vspace.h:2389

## Member Function Documentation

## dequeue()

template<typename T>

T vspace::Queue< T >::dequeue | ( |  | ) |

inline

Definition at line 2456 of file vspace.h.

{
_incoming.wait();
return dequeue_nowait();
}
vspace::Queue::dequeue_nowait
T dequeue_nowait()
Definition vspace.h:2422

## dequeue_nowait()

template<typename T>

T vspace::Queue< T >::dequeue_nowait | ( |  | ) |

inline private

Definition at line 2422 of file vspace.h.

{
_lock.lock();
VRef<Node> node = pop();
T result;
result = node->data;
node.free();
_lock.unlock();
if (_bounded)
_outgoing.post();
return result;
}
vspace::Queue::pop
VRef< Node > pop()
Definition vspace.h:2391

## enqueue()

template<typename T>

void vspace::Queue< T >::enqueue | ( | T | item | ) |

inline

Definition at line 2443 of file vspace.h.

{
if (_bounded)
_outgoing.wait();
enqueue_nowait(item);
}
vspace::Queue::enqueue_nowait
void enqueue_nowait(T item)
Definition vspace.h:2414

## enqueue_nowait()

template<typename T>

void vspace::Queue< T >::enqueue_nowait | ( | T | item | ) |

inline private

Definition at line 2414 of file vspace.h.

{
_lock.lock();
VRef<Node> node = vnew<Node>();
node->data = item;
push(node);
_lock.unlock();
_incoming.post();
}
vspace::Queue::push
void push(VRef< Node > node)
Definition vspace.h:2400
vspace::vnew
VRef< T > vnew()
Definition vspace.h:1872

## pop()

template<typename T>

VRef< Node > vspace::Queue< T >::pop | ( |  | ) |

inline private

Definition at line 2391 of file vspace.h.

{
VRef<Node> result = _head;
if (_head->next.is_null()) {
_head = _tail = vnull<Node>();
} else {
_head = _head->next;
}
return result;
}
vspace::vnull
VRef< T > vnull()
Definition vspace.h:1867

## push()

template<typename T>

void vspace::Queue< T >::push | ( | VRef< Node > | node | ) |

inline private

Definition at line 2400 of file vspace.h.

{
node->next = vnull<Node>();
if (_tail.is_null()) {
_head = _tail = node;
} else {
_tail->next = node;
_tail = node;
}
}

## try_dequeue()

template<typename T>

Result< T > vspace::Queue< T >::try_dequeue | ( |  | ) |

inline

Definition at line 2460 of file vspace.h.

{
if (_incoming.try_wait())
return Result<T>(dequeue_nowait());
else
return Result<T>();
}

## try_enqueue()

template<typename T>

bool vspace::Queue< T >::try_enqueue | ( | T | item | ) |

inline

Definition at line 2448 of file vspace.h.

{
if (_bounded && _outgoing.try_wait()) {
enqueue_nowait(item);
return true;
} else {
return false;
}
}

## Friends And Related Symbol Documentation

## DequeueEvent

template<typename T>
template<typename U>

friend class DequeueEvent

friend

Definition at line 2412 of file vspace.h.

## EnqueueEvent

template<typename T>
template<typename U>

friend class EnqueueEvent

friend

Definition at line 2410 of file vspace.h.

## Field Documentation

## _bounded

template<typename T>

bool vspace::Queue< T >::_bounded

private

Definition at line 2388 of file vspace.h.

## _head

template<typename T>

VRef<Node> vspace::Queue< T >::_head

private

Definition at line 2390 of file vspace.h.

## _incoming

template<typename T>

Semaphore vspace::Queue< T >::_incoming

private

Definition at line 2386 of file vspace.h.

## _lock

template<typename T>

FastLock vspace::Queue< T >::_lock

private

Definition at line 2389 of file vspace.h.

## _outgoing

template<typename T>

Semaphore vspace::Queue< T >::_outgoing

private

Definition at line 2387 of file vspace.h.

## _tail

template<typename T>

VRef<Node> vspace::Queue< T >::_tail

private

Definition at line 2390 of file vspace.h.

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

- kernel/oswrapper/vspace.h