HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

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
datadata CRef (m :: Type -> Type) a
#

A reference-counted value.

typetype CRefCount = Int
#

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).

datadata CRefEvent
#

CRef lifecycle events.

Constructors

Instances3Eq, Show, Pretty
  • Eq CRefEventDefined in kes-agent-crypto-1.2.0.0 · Cardano.KESAgent.Util.RefCounting
  • Show CRefEventDefined in kes-agent-crypto-1.2.0.0 · Cardano.KESAgent.Util.RefCounting
  • Pretty CRefEventDefined in kes-agent-crypto-1.2.0.0 · Cardano.KESAgent.Util.RefCounting
typetype CRefID = Word32
#

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
valuenewCRef
  1. :: (MonadST m, MonadSTM m, MonadThrow m)
  2. => a -> m ()
  3. -> a
  4. -> m (CRef m a)
#

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.

valuereadCRef :: (MonadSTM m, MonadThrow m) => CRef m a -> m a
#

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.