Skip to main content
Log in

Mojo struct

BlockingSpinLock

struct BlockingSpinLock

A basic locking implementation that uses an integer to represent the owner of the lock.

Aliases

  • UNLOCKED = -1: non-zero means locked, -1 means unlocked.

Fields

  • counter (Atomic[int64]): The atomic counter implementing the spin lock.

Implemented traits

AnyType, UnknownDestructibility

Methods

__init__

__init__(out self)

Default constructor.

lock

lock(mut self, owner: Int)

Acquires the lock.

Args:

  • owner (Int): The lock's owner (usually an address).

unlock

unlock(mut self, owner: Int) -> Bool

Releases the lock.

Args:

  • owner (Int): The lock's owner (usually an address).

Returns:

The successful release of the lock.