A reference-counted value.
Modulekes-agent-crypto-1.2.0.0Haskell2010
Cardano.KESAgent.Util.RefCounting
References with a counter-based lifecycle, similar to reference-counted shared pointers. This is useful to implement shared access to scarce resources that require timely destruction (i.e., we cannot rely on GC to run finalizers).
- 6 types
- 12 values
- Packagekes-agent-crypto-1.2.0.0
- Exports18
- LanguageHaskell2010
- LicenceApache-2.0
- SourceRefCounting.hs
Reference count. We use a signed integer so that we can catch cases where a reference is released beyond zero (which shouldn't happen, but we want to be able to detect it when it does).
CRef lifecycle events.
Constructors
CRefEventcreType :: !CRefEventTypewhat happened
creID :: !CRefIDwhich CRef was affected
creCountBefore :: !CRefCountrefcount before the event
creCountAfter :: !CRefCountrefcount after the event
CRef lifecycle event types.
Instances2Eq, Show
Eq CRefEventTypeDefined in kes-agent-crypto-1.2.0.0 · Cardano.KESAgent.Util.RefCountingShow CRefEventTypeDefined in kes-agent-crypto-1.2.0.0 · Cardano.KESAgent.Util.RefCounting
Unique identifier for a CRef. Mainly used for debugging.
Reference underflow exception: this will be thrown when a reference count is released beyond zero (i.e., becomes negative). This is generally a bug, caused by user code releasing a reference that it hasn't acquired.
Instances3Eq, Show, Exception
Eq ReferenceCountUnderflowDefined in kes-agent-crypto-1.2.0.0 · Cardano.KESAgent.Util.RefCountingShow ReferenceCountUnderflowDefined in kes-agent-crypto-1.2.0.0 · Cardano.KESAgent.Util.RefCountingException ReferenceCountUnderflowDefined in kes-agent-crypto-1.2.0.0 · Cardano.KESAgent.Util.RefCounting
Increment the CRef counter such that it will not be finalized until we releaseCRef it again.
Gets the current reference count for the CRef.
Create a fresh CRef. Its counter will be initialized to 1; the caller is
responsible for calling releaseCRef to release it.
newCRef f i creates a CRef with an initial value of i, and a finalizer
f.
Read a CRef without acquiring it. The caller is responsible for making sure the CRef has been acquired appropriately for the duration of the call, and while using the wrapped resource. It is generally preferable to use withCRefValue instead.
Release a CRef by decrementing its counter. When the counter reaches zero, the resource is finalized. Releasing a CRef more often than it has been acquired is an error, and will (eventually) throwIO ReferenceCountUnderflow exceptions.
Create a fresh CRef with a tracer and operate on its value immediately. See newCRefWith.
Create a fresh CRef with a tracer and operate on it immediately. See newCRefWith.