Crate declarative_lock

Crate declarative_lock 

Source
Expand description

§declarative_lock

This module provides a thread-aware lock manager for declarative resource locking. It enables threads to explicitly declare which resources they intend to lock, helping to prevent deadlocks and ensuring safe, coordinated access to shared resources in concurrent environments.

Resources must be declared before they can be locked via DeclarativeLock. Declarations are tracked per thread and managed via DeclarationGuard, which automatically unregisters resources when dropped. The module also provides wrappers for resource locking and guards to ensure proper cleanup and usage tracking.

In addition to resource declaration and management, this module provides the DeclarativeLocker type, which enables safe and controlled locking of declared resources. When a resource is locked, a LockGuard is returned, granting access to the resource while ensuring proper cleanup and usage tracking when the guard is dropped. These wrappers help enforce correct locking discipline and prevent common concurrency issues.

§Features

  • Fine-grained control over resource usage
  • Deadlock prevention through explicit declarations
  • Automatic cleanup of resource declarations
  • Safe access to shared resources

Structs§

DeclarationGuard
A guard that represents a successful declaration of resources in the DeclarativeLock.
DeclarativeLock
A thread-aware lock manager for declarative resource locking.
DeclarativeLocker
A wrapper for managing declarative locking of a resource.
LockGuard
A guard that provides access to a locked resource and ensures proper cleanup.

Enums§

DeclareError
Errors that can occur when declaring resources with DeclarativeLock.
LockError
Errors that can occur when locking a resource with DeclarativeLocker.