setup_read_cleanup

A library for managing data through distinct lifecycle phases: Setup -> Read -> Cleanup.
This crate provides "phased cells", a collection of smart pointer types that enforce a specific lifecycle for the data they manage. This is useful for data that is initialized once, read by multiple threads or tasks for a period, and then explicitly destroyed.
Core Concepts
The lifecycle is divided into three phases:
Setup: The initial phase. The data can be mutably accessed for initialization.Read: The operational phase. The data can only be accessed immutably. This phase is optimized for concurrent, lock-free reads.Cleanup: The final phase. The data can be mutably accessed again for deconstruction or resource cleanup.
Cell Variants
This crate offers several cell variants to suit different concurrency needs:
- [
PhasedCell]: The basic cell. It isSync, allowing it to be shared across threads for reading. However, mutable access viaget_mut_unlockedis not thread-safe and requires the caller to ensure exclusive access. - [
PhasedCellSync]: A thread-safe version that uses astd::sync::Mutexto allow for safe concurrent mutable access during theSetupandCleanupphases. - [
PhasedCellAsync]: (Requires thesetup_read_cleanup-on-tokiofeature) Anasyncversion ofPhasedCellSyncthat uses atokio::sync::Mutex.
Graceful Shutdown
(Requires the setup_read_cleanup-graceful feature)
The graceful module provides wrappers that add graceful shutdown capabilities. When transitioning to the Cleanup phase, these cells will wait for a specified duration for all active read operations to complete.
GracefulPhasedCellGracefulPhasedCellSyncGracefulPhasedCellAsync(Requires both features)
Features
setup_read_cleanup-on-tokio: Enables theasynccell variants (PhasedCellAsync,GracefulPhasedCellAsync) which usetokio::sync.setup_read_cleanup-graceful: Enables thegracefulmodule, which provides cells with graceful shutdown capabilities.
Examples
Using a static PhasedCellSync to initialize data, read it from multiple threads, and then clean it up.
use ;
use thread;
// Declare a static PhasedCellSync instance
static CELL: = new;
Installation
In Cargo.toml, write this crate as a dependency:
[]
= "0.3.1"
Supported Rust versions
This crate supports Rust 1.74.1 or later.
)
License
Copyright (C) 2025 Takayuki Sato
This program is free software under MIT License. See the file LICENSE in this distribution for more details.