My Project
Loading...
Searching...
No Matches
Data Structures | Public Member Functions | Private Member Functions | Private Attributes | Friends
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< Ttry_dequeue ()
 

Private Member Functions

VRef< Nodepop ()
 
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.

2435 :
2436 _incoming(0),
2438 _bounded(bound != 0),
2439 _head(),
2440 _tail(),
2441 _lock() {
2442 }
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
Semaphore _incoming
Definition: vspace.h:2386
Semaphore _outgoing
Definition: vspace.h:2387
bool _bounded
Definition: vspace.h:2388
VRef< Node > _head
Definition: vspace.h:2390
VRef< Node > _tail
Definition: vspace.h:2390
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.

2456 {
2457 _incoming.wait();
2458 return dequeue_nowait();
2459 }
T dequeue_nowait()
Definition: vspace.h:2422

◆ dequeue_nowait()

template<typename T >
T vspace::Queue< T >::dequeue_nowait ( )
inlineprivate

Definition at line 2422 of file vspace.h.

2422 {
2423 _lock.lock();
2424 VRef<Node> node = pop();
2425 T result;
2426 result = node->data;
2427 node.free();
2428 _lock.unlock();
2429 if (_bounded)
2430 _outgoing.post();
2431 return result;
2432 }
VRef< Node > pop()
Definition: vspace.h:2391
return result
Definition: facAbsBiFact.cc:75
STATIC_VAR jList * T
Definition: janet.cc:30

◆ enqueue()

template<typename T >
void vspace::Queue< T >::enqueue ( T  item)
inline

Definition at line 2443 of file vspace.h.

2443 {
2444 if (_bounded)
2445 _outgoing.wait();
2446 enqueue_nowait(item);
2447 }
void enqueue_nowait(T item)
Definition: vspace.h:2414

◆ enqueue_nowait()

template<typename T >
void vspace::Queue< T >::enqueue_nowait ( T  item)
inlineprivate

Definition at line 2414 of file vspace.h.

2414 {
2415 _lock.lock();
2416 VRef<Node> node = vnew<Node>();
2417 node->data = item;
2418 push(node);
2419 _lock.unlock();
2420 _incoming.post();
2421 }
void push(VRef< Node > node)
Definition: vspace.h:2400

◆ pop()

template<typename T >
VRef< Node > vspace::Queue< T >::pop ( )
inlineprivate

Definition at line 2391 of file vspace.h.

2391 {
2392 VRef<Node> result = _head;
2393 if (_head->next.is_null()) {
2394 _head = _tail = vnull<Node>();
2395 } else {
2396 _head = _head->next;
2397 }
2398 return result;
2399 }

◆ push()

template<typename T >
void vspace::Queue< T >::push ( VRef< Node node)
inlineprivate

Definition at line 2400 of file vspace.h.

2400 {
2401 node->next = vnull<Node>();
2402 if (_tail.is_null()) {
2403 _head = _tail = node;
2404 } else {
2405 _tail->next = node;
2406 _tail = node;
2407 }
2408 }

◆ try_dequeue()

template<typename T >
Result< T > vspace::Queue< T >::try_dequeue ( )
inline

Definition at line 2460 of file vspace.h.

2460 {
2461 if (_incoming.try_wait())
2462 return Result<T>(dequeue_nowait());
2463 else
2464 return Result<T>();
2465 }

◆ try_enqueue()

template<typename T >
bool vspace::Queue< T >::try_enqueue ( T  item)
inline

Definition at line 2448 of file vspace.h.

2448 {
2449 if (_bounded && _outgoing.try_wait()) {
2450 enqueue_nowait(item);
2451 return true;
2452 } else {
2453 return false;
2454 }
2455 }

Friends And Related Function 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: