13 releases

0.1.12 Oct 3, 2024
0.1.11 Jun 26, 2024
0.1.6 May 27, 2024
0.1.4 Nov 23, 2023

#346 in Memory management

Download history 124/week @ 2024-07-25 17/week @ 2024-08-01 1/week @ 2024-08-22 4/week @ 2024-08-29 3/week @ 2024-09-05 20/week @ 2024-09-12 20/week @ 2024-09-26 196/week @ 2024-10-03 14/week @ 2024-10-10 15/week @ 2024-10-17 22/week @ 2024-10-24 44/week @ 2024-10-31

100 downloads per month
Used in 2 crates (via batch-channel)

MIT license

17KB
280 lines

Thread-Safe Split Reference Counts

splitrc provides a pair of reference counts that together manage the lifetime of an object. The object is notified when either half's count reaches zero.

It is primarily aimed at implementing ownership of channel types, where the channel needs notification when one half is fully dropped.

The implementation stores two 32-bit counters in a shared 64-bit atomic. On 64-bit platforms, atomic increment and decrements are used. On 32-bit platforms, increments and decrements are a CAS loop.

Four billion references should be plenty. Exceeding that leads to a panic.

The pointers are arbitrarily named [Tx] and [Rx] to indicate their intended use by channels.

# struct MyValue {}
# impl splitrc::Notify for MyValue {}
let (tx, rx) = splitrc::new(MyValue {});

Dependencies

~0–24MB
~332K SLoC