Module arc_swap::gen_lock

source ·
Expand description

Customization of where and how the generation lock works.

By default, all the ArcSwapAny instances share the same generation lock. This is to save space in them (they have the same size as a single pointer), because the default lock is quite a large data structure (it’s sharded, to prevent too much contention between different threads). This has the disadvantage that a lock on one instance influences another instance.

The things in this module allow customizing how the lock behaves. The default one is Global. If you want to use independent but unsharded lock, use the PrivateUnsharded (or the IndependentArcSwap type alias).

Or you can implement your own lock, but you probably should study the internals of the library first.

Not Implemented Yet

These variants would probably make sense, but haven’t been written yet:

  • A lock storage that is shared, but only between a certain group of pointers. It could be either as a reference (but then each ArcSwap would get a bit bigger), or a macro that could generate an independent but global storage.

Structs

The default, global lock.
An alternative to PrivateUnsharded, but with configurable number of shards.
A single „shard“ that is stored inline, inside the corresponding ArcSwap. Therefore, locks on each instance won’t influence any other instances. On the other hand, the ArcSwap itself gets bigger and doesn’t have multiple shards, so concurrent uses might contend each other a bit.
A single shard.

Traits

Abstraction of the place where generation locks are stored.