add CCRef.{get_then_incr,incr_then_get} functions

This commit is contained in:
Simon Cruanes 2016-04-15 15:04:31 +02:00
parent 55a4c7ef7a
commit e2bc0cf55a
2 changed files with 16 additions and 0 deletions

View file

@ -21,6 +21,14 @@ let iter f r = f !r
let update f r = r := (f !r)
let incr_then_get r =
incr r; !r
let get_then_incr r =
let x = !r in
incr r;
x
let compare f r1 r2 = f !r1 !r2
let equal f r1 r2 = f !r1 !r2

View file

@ -24,6 +24,14 @@ val iter : ('a -> unit) -> 'a t -> unit
val update : ('a -> 'a) -> 'a t -> unit
(** Update the reference's content with the given function *)
val incr_then_get : int t -> int
(** [incr_then_get r] increments [r] and returns its new value, think [++ r]
@since NEXT_RELEASE *)
val get_then_incr : int t -> int
(** [get_then_incr r] increments [r] and returns its old value, think [r++]
@since NEXT_RELEASE *)
val compare : 'a ord -> 'a t ord
val equal : 'a eq -> 'a t eq