@include <TypedSharedStack>

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

Reads and writes are atomic and concurrency-safe.

The stack can be encrypted for security.

Methods

@TypedSharedStack.set_type

Scope: public

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

Usage: @TypedSharedStack.set_type $type

Parameters

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

@TypedSharedStack.push

Scope: public

Adds a value to the top of the shared stack, enforcing the specified type.

Usage: @TypedSharedStack.push $value

Parameters

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

@TypedSharedStack.size

Scope: public

Echoes the number of elements in the stack.

Usage: @TypedSharedStack.size

@TypedSharedStack.pop

Scope: public

Pops the top element off the stack and echoes it.

Usage: @TypedSharedStack.pop

@TypedSharedStack.top

Scope: public

Echoes the top element of the stack without removing it.

Usage: @TypedSharedStack.top

@TypedSharedStack.clear

Scope: public

Removes all elements from the stack.

Usage: @TypedSharedStack.clear

@TypedSharedStack.empty

Scope: public

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

Usage: @TypedSharedStack.empty

@TypedSharedStack.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: @TypedSharedStack.setEncrypted $value

Parameters

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

@TypedSharedStack.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: @TypedSharedStack.lock

@TypedSharedStack.unlock

Scope: public

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

This also resets the extended_lock flag to 0.

Usage: @TypedSharedStack.unlock