A* Pathfinding Project  3.6.6
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
ThreadControlQueue Class Reference

Classes

class  QueueTerminationException
 

Public Member Functions

 ThreadControlQueue (int numReceivers)
 Create a new queue with the specified number of receivers.
 
void Block ()
 Block queue, all calls to Pop will block until Unblock is called.
 
void Lock ()
 Aquires a lock on this queue.
 
Path Pop ()
 Pops the next item off the queue.
 
Path PopNoBlock (bool blockedBefore)
 Pops the next item off the queue, this call will not block.
 
void Push (Path p)
 Push a path to the end of the queue.
 
void PushFront (Path p)
 Push a path to the front of the queue.
 
void ReceiverTerminated ()
 Call when a receiver was terminated in other ways than by a QueueTerminationException.
 
void TerminateReceivers ()
 All calls to Pop and PopNoBlock will now generate exceptions.
 
void Unblock ()
 Unblock queue.
 
void Unlock ()
 Releases the lock on this queue.
 

Properties

bool AllReceiversBlocked [get]
 True if blocking and all receivers are waiting for unblocking.
 
bool IsEmpty [get]
 True if the queue is empty.
 
bool IsTerminating [get]
 True if TerminateReceivers has been called.
 

Private Member Functions

void Starving ()
 

Private Attributes

ManualResetEvent block = new ManualResetEvent(true)
 
bool blocked = false
 
int blockedReceivers = 0
 
Path head
 
System.Object lockObj = new System.Object()
 
int numReceivers
 
bool starving = false
 
Path tail
 
bool terminate = false
 

Constructor & Destructor Documentation

ThreadControlQueue ( int  numReceivers)

Create a new queue with the specified number of receivers.

It is important that the number of receivers is fixed. Properties like AllReceiversBlocked rely on knowing the exact number of receivers using the Pop (or PopNoBlock) methods.

Member Function Documentation

void Block ( )

Block queue, all calls to Pop will block until Unblock is called.

void Lock ( )

Aquires a lock on this queue.

Must be paired with a call to Unlock

Path Pop ( )

Pops the next item off the queue.

This call will block if there are no items in the queue or if the queue is currently blocked.

Returns
A Path object, guaranteed to be not null.
Exceptions
QueueTerminationExceptionif TerminateReceivers has been called.
System.InvalidOperationExceptionif more receivers get blocked than the fixed count sent to the constructor
Path PopNoBlock ( bool  blockedBefore)

Pops the next item off the queue, this call will not block.

To ensure stability, the caller must follow this pattern. 1. Call PopNoBlock(false), if a null value is returned, wait for a bit (e.g yield return null in a Unity coroutine) 2. try again with PopNoBlock(true), if still null, wait for a bit 3. Repeat from step 2.

Exceptions
QueueTerminationExceptionif TerminateReceivers has been called.
System.InvalidOperationExceptionif more receivers get blocked than the fixed count sent to the constructor
void Push ( Path  p)

Push a path to the end of the queue.

void PushFront ( Path  p)

Push a path to the front of the queue.

void ReceiverTerminated ( )

Call when a receiver was terminated in other ways than by a QueueTerminationException.

After this call, the receiver should be dead and not call anything else in this class.

void Starving ( )
private
void TerminateReceivers ( )

All calls to Pop and PopNoBlock will now generate exceptions.

void Unblock ( )

Unblock queue.

Calls to Pop will not block anymore.

See Also
Block
void Unlock ( )

Releases the lock on this queue.

Member Data Documentation

ManualResetEvent block = new ManualResetEvent(true)
private
bool blocked = false
private
int blockedReceivers = 0
private
Path head
private
System.Object lockObj = new System.Object()
private
int numReceivers
private
bool starving = false
private
Path tail
private
bool terminate = false
private

Property Documentation

bool AllReceiversBlocked
get

True if blocking and all receivers are waiting for unblocking.

bool IsEmpty
get

True if the queue is empty.

bool IsTerminating
get

True if TerminateReceivers has been called.


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