@include <TypedSharedQueue>

The TypedSharedQueue class provides a shared queue implementation which enforces type restrictions on its elements. After setting the queue’s type, all elements must be pointers to objects of that type or its subclasses.

Reads and writes are atomic and concurrency-safe.

The queue can be encrypted for security.

Methods

@TypedSharedQueue.set_type

Scope: public

Sets the type of elements that this shared queue will hold. This method must be called before adding elements to the queue. The queue’s type cannot be changed after elements have been added.

Usage: @TypedSharedQueue.set_type $type

Parameters

  • type
    • Type: primitive
    • The type to enforce for the elements of this shared queue.

@TypedSharedQueue.enqueue

Scope: public

Adds a value to the end of the shared queue, enforcing the specified type.

Usage: @TypedSharedQueue.enqueue $value

Parameters

  • value
    • Type: primitive
    • The value to add to the shared queue.

@TypedSharedQueue.size

Scope: public

Echoes the number of elements in the queue.

Usage: @TypedSharedQueue.size

@TypedSharedQueue.dequeue

Scope: public

Removes the front element from the queue and echoes it.

Usage: @TypedSharedQueue.dequeue

@TypedSharedQueue.front

Scope: public

Echoes the front element of the queue without removing it.

Usage: @TypedSharedQueue.front

@TypedSharedQueue.back

Scope: public

Echoes the back element of the queue without removing it.

Usage: @TypedSharedQueue.back

@TypedSharedQueue.clear

Scope: public

Removes all elements from the queue.

Usage: @TypedSharedQueue.clear

@TypedSharedQueue.empty

Scope: public

Echoes “true” if the queue is empty, “false” otherwise.

Usage: @TypedSharedQueue.empty

@TypedSharedQueue.setEncrypted

Scope: public

Sets whether the object should be encrypted. Encrypting the object can mitigate unauthorized reads by other processes.

This cannot be changed after the object has been used.

Usage: @TypedSharedQueue.setEncrypted $value

Parameters

  • value
    • Type: primitive
    • ‘1’ or ‘true’ enables encryption, any other value disables it.

@TypedSharedQueue.lock

Scope: public

Locks the shared object for exclusive access.

Once locked, only the process which locked it can access the object until it is unlocked.

Attempts by other processes access the object while it is locked will block until it is unlocked.

Using this method (as opposed to the internal _lock method) sets the extended_lock flag to 1, indicating that the lock should not be dropped until explicitly unlocked. I.e., subsequent calls to _unlock (internal) will not release the lock until unlock (public) is called.

Usage: @TypedSharedQueue.lock

@TypedSharedQueue.unlock

Scope: public

Unlocks the shared object, allowing other processes to access it.

This also resets the extended_lock flag to 0.

Usage: @TypedSharedQueue.unlock