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

Queue of paths to be processed by the system. More...

Detailed Description

Queue of paths to be processed by the system.

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
 
int blockedReceivers
 Number of receiver threads that are currently blocked.
 
Path head
 
readonly System.Object lockObj = new System.Object()
 
readonly int numReceivers
 
bool starving
 True while head == null.
 
Path tail
 
bool terminate
 True after TerminateReceivers has been called.
 

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
private
int blockedReceivers
private

Number of receiver threads that are currently blocked.

This is only modified while a thread has a lock on lockObj

Path head
private
readonly System.Object lockObj = new System.Object()
private
readonly int numReceivers
private
bool starving
private

True while head == null.

This is only modified while a thread has a lock on lockObj

Path tail
private
bool terminate
private

True after TerminateReceivers has been called.

All receivers will be terminated when they next call Pop.

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: