mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 03:47:59 -04:00
fuck vendoring atomic
This commit is contained in:
parent
18ae3bc41b
commit
e2e2c4baac
8 changed files with 177 additions and 6 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -1,6 +1,3 @@
|
||||||
[submodule "vendor/opentelemetry-proto"]
|
[submodule "vendor/opentelemetry-proto"]
|
||||||
path = vendor/opentelemetry-proto
|
path = vendor/opentelemetry-proto
|
||||||
url = https://github.com/open-telemetry/opentelemetry-proto
|
url = https://github.com/open-telemetry/opentelemetry-proto
|
||||||
[submodule "vendor/atomic"]
|
|
||||||
path = vendor/atomic
|
|
||||||
url = https://github.com/c-cube/ocaml-atomic.git
|
|
||||||
|
|
|
||||||
52
src/atomic/atomic.post412.mli
Normal file
52
src/atomic/atomic.post412.mli
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
|
||||||
|
(**************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* OCaml *)
|
||||||
|
(* *)
|
||||||
|
(* Stephen Dolan, University of Cambridge *)
|
||||||
|
(* Gabriel Scherer, projet Partout, INRIA Paris-Saclay *)
|
||||||
|
(* *)
|
||||||
|
(* Copyright 2017-2018 University of Cambridge. *)
|
||||||
|
(* Copyright 2020 Institut National de Recherche en Informatique et *)
|
||||||
|
(* en Automatique. *)
|
||||||
|
(* *)
|
||||||
|
(* All rights reserved. This file is distributed under the terms of *)
|
||||||
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
||||||
|
(* special exception on linking described in the file LICENSE. *)
|
||||||
|
(* *)
|
||||||
|
(**************************************************************************)
|
||||||
|
|
||||||
|
(** Atomic references.
|
||||||
|
*)
|
||||||
|
|
||||||
|
(** An atomic (mutable) reference to a value of type ['a]. *)
|
||||||
|
type 'a t = 'a Stdlib.Atomic.t
|
||||||
|
|
||||||
|
(** Create an atomic reference. *)
|
||||||
|
val make : 'a -> 'a t
|
||||||
|
|
||||||
|
(** Get the current value of the atomic reference. *)
|
||||||
|
val get : 'a t -> 'a
|
||||||
|
|
||||||
|
(** Set a new value for the atomic reference. *)
|
||||||
|
val set : 'a t -> 'a -> unit
|
||||||
|
|
||||||
|
(** Set a new value for the atomic reference, and return the current value. *)
|
||||||
|
val exchange : 'a t -> 'a -> 'a
|
||||||
|
|
||||||
|
(** [compare_and_set r seen v] sets the new value of [r] to [v] only
|
||||||
|
if its current value is physically equal to [seen] -- the
|
||||||
|
comparison and the set occur atomically. Returns [true] if the
|
||||||
|
comparison succeeded (so the set happened) and [false]
|
||||||
|
otherwise. *)
|
||||||
|
val compare_and_set : 'a t -> 'a -> 'a -> bool
|
||||||
|
|
||||||
|
(** [fetch_and_add r n] atomically increments the value of [r] by [n],
|
||||||
|
and returns the current value (before the increment). *)
|
||||||
|
val fetch_and_add : int t -> int -> int
|
||||||
|
|
||||||
|
(** [incr r] atomically increments the value of [r] by [1]. *)
|
||||||
|
val incr : int t -> unit
|
||||||
|
|
||||||
|
(** [decr r] atomically decrements the value of [r] by [1]. *)
|
||||||
|
val decr : int t -> unit
|
||||||
52
src/atomic/atomic.pre412.mli
Normal file
52
src/atomic/atomic.pre412.mli
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
|
||||||
|
(**************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* OCaml *)
|
||||||
|
(* *)
|
||||||
|
(* Stephen Dolan, University of Cambridge *)
|
||||||
|
(* Gabriel Scherer, projet Partout, INRIA Paris-Saclay *)
|
||||||
|
(* *)
|
||||||
|
(* Copyright 2017-2018 University of Cambridge. *)
|
||||||
|
(* Copyright 2020 Institut National de Recherche en Informatique et *)
|
||||||
|
(* en Automatique. *)
|
||||||
|
(* *)
|
||||||
|
(* All rights reserved. This file is distributed under the terms of *)
|
||||||
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
||||||
|
(* special exception on linking described in the file LICENSE. *)
|
||||||
|
(* *)
|
||||||
|
(**************************************************************************)
|
||||||
|
|
||||||
|
(** Atomic references.
|
||||||
|
*)
|
||||||
|
|
||||||
|
(** An atomic (mutable) reference to a value of type ['a]. *)
|
||||||
|
type 'a t
|
||||||
|
|
||||||
|
(** Create an atomic reference. *)
|
||||||
|
val make : 'a -> 'a t
|
||||||
|
|
||||||
|
(** Get the current value of the atomic reference. *)
|
||||||
|
val get : 'a t -> 'a
|
||||||
|
|
||||||
|
(** Set a new value for the atomic reference. *)
|
||||||
|
val set : 'a t -> 'a -> unit
|
||||||
|
|
||||||
|
(** Set a new value for the atomic reference, and return the current value. *)
|
||||||
|
val exchange : 'a t -> 'a -> 'a
|
||||||
|
|
||||||
|
(** [compare_and_set r seen v] sets the new value of [r] to [v] only
|
||||||
|
if its current value is physically equal to [seen] -- the
|
||||||
|
comparison and the set occur atomically. Returns [true] if the
|
||||||
|
comparison succeeded (so the set happened) and [false]
|
||||||
|
otherwise. *)
|
||||||
|
val compare_and_set : 'a t -> 'a -> 'a -> bool
|
||||||
|
|
||||||
|
(** [fetch_and_add r n] atomically increments the value of [r] by [n],
|
||||||
|
and returns the current value (before the increment). *)
|
||||||
|
val fetch_and_add : int t -> int -> int
|
||||||
|
|
||||||
|
(** [incr r] atomically increments the value of [r] by [1]. *)
|
||||||
|
val incr : int t -> unit
|
||||||
|
|
||||||
|
(** [decr r] atomically decrements the value of [r] by [1]. *)
|
||||||
|
val decr : int t -> unit
|
||||||
15
src/atomic/dune
Normal file
15
src/atomic/dune
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
(library
|
||||||
|
(name opentelemetry_atomic)
|
||||||
|
(synopsis "Compatibility package for the Atomic module for opentelemetry")
|
||||||
|
(public_name opentelemetry.atomic)
|
||||||
|
(modules atomic))
|
||||||
|
|
||||||
|
(executable
|
||||||
|
(modules gen)
|
||||||
|
(name gen))
|
||||||
|
|
||||||
|
(rule
|
||||||
|
(targets atomic.ml atomic.mli atomic.ml)
|
||||||
|
(deps atomic.pre412.mli atomic.post412.mli)
|
||||||
|
(action (run ./gen.exe)))
|
||||||
54
src/atomic/gen.ml
Normal file
54
src/atomic/gen.ml
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
|
||||||
|
|
||||||
|
let atomic_before_412 = {|
|
||||||
|
type 'a t = {mutable x: 'a}
|
||||||
|
let[@inline] make x = {x}
|
||||||
|
let[@inline] get {x} = x
|
||||||
|
let[@inline] set r x = r.x <- x
|
||||||
|
|
||||||
|
let[@inline never] exchange r x =
|
||||||
|
(* critical section *)
|
||||||
|
let y = r.x in
|
||||||
|
r.x <- x;
|
||||||
|
(* end critical section *)
|
||||||
|
y
|
||||||
|
|
||||||
|
let[@inline never] compare_and_set r seen v =
|
||||||
|
(* critical section *)
|
||||||
|
if r.x == seen then (
|
||||||
|
r.x <- v;
|
||||||
|
true
|
||||||
|
) else false
|
||||||
|
|
||||||
|
let[@inline never] fetch_and_add r x =
|
||||||
|
let v = r.x in
|
||||||
|
r.x <- x + r.x;
|
||||||
|
v
|
||||||
|
|
||||||
|
let[@inline never] incr r = r.x <- 1 + r.x
|
||||||
|
let[@inline never] decr r = r.x <- r.x - 1
|
||||||
|
|}
|
||||||
|
|
||||||
|
let atomic_after_412 = {|include Stdlib.Atomic|}
|
||||||
|
|
||||||
|
let write_file file s =
|
||||||
|
let oc = open_out file in output_string oc s; close_out oc
|
||||||
|
|
||||||
|
let copy_file file1 file2 =
|
||||||
|
let oc = open_out file2 in
|
||||||
|
let ic = open_in file1 in
|
||||||
|
let buf = Bytes.create 1024 in
|
||||||
|
try
|
||||||
|
while true do
|
||||||
|
let n = input ic buf 0 (Bytes.length buf) in
|
||||||
|
if n=0 then raise End_of_file;
|
||||||
|
output oc buf 0 n
|
||||||
|
done
|
||||||
|
with End_of_file -> ()
|
||||||
|
|
||||||
|
let () =
|
||||||
|
let version = Scanf.sscanf Sys.ocaml_version "%d.%d.%s" (fun x y _ -> x,y) in
|
||||||
|
write_file "atomic.ml" (if version >= (4,12) then atomic_after_412 else atomic_before_412);
|
||||||
|
copy_file (if version >= (4,12) then "atomic.post412.mli" else "atomic.pre412.mli") "atomic.mli" ;
|
||||||
|
()
|
||||||
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
(library
|
(library
|
||||||
(name opentelemetry_client_ocurl)
|
(name opentelemetry_client_ocurl)
|
||||||
(public_name opentelemetry-client-ocurl)
|
(public_name opentelemetry-client-ocurl)
|
||||||
(libraries opentelemetry curl ocaml-protoc threads
|
(libraries opentelemetry opentelemetry.atomic
|
||||||
atomic mtime mtime.clock.os))
|
curl ocaml-protoc threads
|
||||||
|
mtime mtime.clock.os))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
module OT = Opentelemetry
|
module OT = Opentelemetry
|
||||||
open Opentelemetry
|
open Opentelemetry
|
||||||
|
module Atomic = Opentelemetry_atomic.Atomic
|
||||||
|
|
||||||
let[@inline] (let@) f x = f x
|
let[@inline] (let@) f x = f x
|
||||||
|
|
||||||
|
|
|
||||||
1
vendor/atomic
vendored
1
vendor/atomic
vendored
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 12dc7c84f79606a8a0026ba1eb7856b3cdf6cab6
|
|
||||||
Loading…
Add table
Reference in a new issue