Crate ranked_semaphore

Source
Expand description

§Ranked Semaphore - High-Performance Priority Semaphore

A completely safe (zero unsafe) high-performance semaphore implementation with priority queuing. Design goals: zero-cost abstractions, ultra-low latency, minimal memory footprint.

§Core Features

  • High Performance: Uncontended path <10ns latency
  • Zero unsafe: 100% safe Rust code
  • Dynamic Priority: Support for arbitrary priority levels
  • Zero Cost: Memory allocation only for actively used priorities
  • Batch Optimized: Smart batching reduces lock contention
  • Cache Friendly: Optimized memory layout

§Usage Example

use ranked_semaphore::RankedSemaphore;

// Create a semaphore with 3 permits
let semaphore = RankedSemaphore::new_fifo(3);

// Default priority acquisition
let _permit1 = semaphore.acquire().await?;

// High priority acquisition
let _permit2 = semaphore.acquire_with_priority(10).await?;

// Batch acquisition
let _permits = semaphore.acquire_many_with_priority(5, 2).await?;

Modules§

prelude
Prelude module for commonly used types.

Structs§

Acquire
Acquire operation Future
AcquireError
Error returned from acquire operations when the semaphore has been closed.
AcquireOwned
Owned acquire operation Future
OwnedRankedSemaphorePermit
Semaphore permit (owned version)
PriorityConfig
Configuration for priority-based queue strategies.
RankedSemaphore
High-performance priority semaphore
RankedSemaphorePermit
Semaphore permit (borrowed version)

Enums§

QueueStrategy
Queue strategy for waiters at a given priority level.
TryAcquireError
Error returned from try_acquire operations.