A* Pathfinding Project  4.1.7
The A* Pathfinding Project for Unity 3D
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. More...
 
void Block ()
 Block queue, all calls to Pop will block until Unblock is called. More...
 
void Lock ()
 Aquires a lock on this queue. More...
 
Path Pop ()
 Pops the next item off the queue. More...
 
Path PopNoBlock (bool blockedBefore)
 Pops the next item off the queue, this call will not block. More...
 
void Push (Path path)
 Push a path to the end of the queue. More...
 
void PushFront (Path path)
 Push a path to the front of the queue. More...
 
void ReceiverTerminated ()
 Call when a receiver was terminated in other ways than by a QueueTerminationException. More...
 
void TerminateReceivers ()
 All calls to Pop and PopNoBlock will now generate exceptions. More...
 
void Unblock ()
 Unblock queue. More...
 
void Unlock ()
 Releases the lock on this queue. More...
 

Properties

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

Private Member Functions

void Starving ()
 

Private Attributes

ManualResetEvent block = new ManualResetEvent(true)
 
bool blocked
 
int blockedReceivers
 Number of receiver threads that are currently blocked. More...
 
Path head
 
readonly System.Object lockObj = new System.Object()
 
readonly int numReceivers
 
bool starving
 True while head == null. More...
 
Path tail
 
bool terminate
 True after TerminateReceivers has been called. More...
 

Constructor & Destructor Documentation

◆ ThreadControlQueue()

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

◆ Block()

void Block ( )

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

◆ Lock()

void Lock ( )

Aquires a lock on this queue.

Must be paired with a call to Unlock

◆ Pop()

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

◆ PopNoBlock()

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

◆ Push()

void Push ( Path  path)

Push a path to the end of the queue.

◆ PushFront()

void PushFront ( Path  path)

Push a path to the front of the queue.

◆ ReceiverTerminated()

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.

◆ Starving()

void Starving ( )
private

◆ TerminateReceivers()

void TerminateReceivers ( )

All calls to Pop and PopNoBlock will now generate exceptions.

◆ Unblock()

void Unblock ( )

Unblock queue.

Calls to Pop will not block anymore.

See also
Block

◆ Unlock()

void Unlock ( )

Releases the lock on this queue.

Member Data Documentation

◆ block

ManualResetEvent block = new ManualResetEvent(true)
private

◆ blocked

bool blocked
private

◆ blockedReceivers

int blockedReceivers
private

Number of receiver threads that are currently blocked.

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

◆ head

Path head
private

◆ lockObj

readonly System.Object lockObj = new System.Object()
private

◆ numReceivers

readonly int numReceivers
private

◆ starving

bool starving
private

True while head == null.

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

◆ tail

Path tail
private

◆ terminate

bool terminate
private

True after TerminateReceivers has been called.

All receivers will be terminated when they next call Pop.

Property Documentation

◆ AllReceiversBlocked

bool AllReceiversBlocked
get

True if blocking and all receivers are waiting for unblocking.

◆ IsEmpty

bool IsEmpty
get

True if the queue is empty.

◆ IsTerminating

bool IsTerminating
get

True if TerminateReceivers has been called.


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