Trait dynalock::Locking [] [src]

pub trait Locking {
    type AcquireLockInputType;
    type RefreshLockInputType;
    type ReleaseLockInputType;
    fn acquire_lock(
        &mut self,
        input: &Self::AcquireLockInputType
    ) -> Result<Instant, DynaError>;
fn refresh_lock(
        &mut self,
        input: &Self::RefreshLockInputType
    ) -> Result<(), DynaError>;
fn remaining(&self, instant: Instant) -> Option<Duration>; fn release_lock(
        &mut self,
        _input: &Self::ReleaseLockInputType
    ) -> Result<(), DynaError> { ... } }

The Locking trait provides a contractual API that providers implement the Dynalock algorithm using the particular provider's primitives.

Each method has an associated type on the trait for its input. Providers must implement all of the associated types to provide input to this trait's methods.

All trait methods return Result<T, E> where E is always DynaError except for remaining where it returns Option<Duration>.

Associated Types

Associated type for the acquire_lock method input type.

Associated type for the refresh_lock method input type.

Associated type for the release_lock method input type.

Required Methods

Try to acquire a lock on a shared resource.

If successful this method must return an std::time::Instant that marks the point in time when the lease on a lock was obtained. Providers should only generate an Instant after the last I/O call is made.

Try to refresh the current lock data structure.

This is useful when acquire_lock fails with DynaErrorKind::LockAlreadyAcquired error and the provider doesn't support a Compare-And-Swap primitive and only supports the compare-and-set variant.

When acquire_lock is successful it returns an std::time::Instant which is used to track the time from when the lease was issued. This method is used to safely calculate the time or duration left since acquire_lock was called. If the return value is None this means that the lock lease has expired and you must stop mutating the shared resource immediately.

Provided Methods

This optional method is only useful in rare situations and highly depends on the provider's implementation and primitives supported. Providers should implement this method to release the lock by clearing the fence token.

Implementors