package picos
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=544804c0bde4b29764f82f04e7defed7c06bc43e5a6ce3f7fdc326cb54a7f066
sha512=4c93427e477fb52374a554a8b9c4c92836a9b5899161275d1473269ab526a1f59177209140631ed763a55be375855dea12f076e18bf4124522414986c0e257be
doc/picos.rc/Picos_rc/module-type-S/index.html
Module type Picos_rc.S
Source
An externally reference counted resource.
ℹ️ This is intended for cases where a resource needs to be safely shared between multiple independent threads of control whether they are fibers, threads, or domains. In that use case you typically need to increment the reference count before handing the resource from one independent thread of control to another and the other independent thread of control then becomes responsible for decrementing the reference count after being done with the resource.
val create : ?dispose:bool -> Resource.t -> t
create resource
adds an entry for the resource with an initial reference count of 1
to the table for the resource and returns the resource as a value of the opaque alias type.
The optional dispose
argument defaults to true
. When explicitly specified as ~dispose:false
, the resource will not be disposed when the reference count becomes zero. This is intended for special cases where a resource is e.g. managed outside of the control of the user program.
val unsafe_get : t -> Resource.t
unsafe_get opaque_resource
casts the opaque alias type back to the resource type.
⚠️ This should only be called and the resource used either after creating the reference counting entry or after incrementing the reference count and before the matching decrement.
val incr : t -> unit
incr opaque_resource
tries to find the entry for the resource and increment the reference count.
val decr : ?close:bool -> t -> unit
decr opaque_resource
tries to find the entry for the resource and decrement the reference count. If the reference count becomes zero, the entry for the resource will be removed and the resource will be disposed, unless ~dispose:false
was specified for create
.
The optional close
argument defaults to false
. When explicitly specified as ~close:true
the resource will be marked as closed and attempts to increment the reference will fail.
type info = {
resource : Resource.t;
(*The resource.
*)count : int;
(*Reference count. This may be
*)0
.closed : bool;
dispose : bool;
bt : Printexc.raw_backtrace;
}
Information on a resource.