BEAM friendly spinlocks for Elixir/Erlang.
This module provides a very simple API for managing locks inside a BEAM instance. It's modeled on spinlocks, but works through message passing rather than loops. Locks can have multiple slots to enable arbitrary numbers of associated processes. The moment a slot is freed, the next awaiting process acquires the lock.
All of this is done in a simple Erlang process so there's very little dependency, and management is extremely simple.| acquire/1 | Acquires a lock for the current process. |
| attempt/1 | Attempts to acquire a lock for the current process. |
| execute/2 | Executes a function when a lock can be acquired. |
| handle_call/3 | |
| init/1 | |
| new/1 | Creates a new lock with a provided concurrency factor. |
| new/2 | Creates a new lock with a provided concurrency factor. |
| release/1 | Releases a lock held by the current process. |
acquire(ServerName) -> ok
Acquires a lock for the current process.
This will block until a lock can be acquired.attempt(ServerName) -> Result
Attempts to acquire a lock for the current process.
In the case there are no slots available, an error will be returned immediately rather than waiting.execute(ServerName, Exec) -> ok
Executes a function when a lock can be acquired.
The lock is automatically released after the function has completed execution; there's no need to manually release.handle_call(X1, Caller, Lock) -> any()
init(Slots) -> any()
new(Slots::pos_integer()) -> {ok, pid()} | ignore | {error, term()}
Creates a new lock with a provided concurrency factor.
new(Slots::pos_integer(), Args::list()) -> {ok, pid()} | ignore | {error, term()}
Creates a new lock with a provided concurrency factor.
release(ServerName) -> ok
Releases a lock held by the current process.
Generated by EDoc