mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
add shims for Atomic on OCaml < 4.12
This commit is contained in:
parent
911db76864
commit
3f3d3e3464
3 changed files with 52 additions and 2 deletions
9
src/dune
9
src/dune
|
|
@ -18,3 +18,12 @@
|
|||
(with-stdout-to
|
||||
%{targets}
|
||||
(run %{bin}))))
|
||||
|
||||
(rule
|
||||
(targets Tiny_httpd_atomic_.ml)
|
||||
(deps
|
||||
(:bin ./gen/mkshims.exe))
|
||||
(action
|
||||
(with-stdout-to
|
||||
%{targets}
|
||||
(run %{bin}))))
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
(executable
|
||||
(name gentags))
|
||||
(executables
|
||||
(names gentags mkshims))
|
||||
|
|
|
|||
41
src/gen/mkshims.ml
Normal file
41
src/gen/mkshims.ml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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] exchange r x =
|
||||
let y = r.x in
|
||||
r.x <- x;
|
||||
y
|
||||
|
||||
let[@inline] compare_and_set r seen v =
|
||||
if r.x == seen then (
|
||||
r.x <- v;
|
||||
true
|
||||
) else false
|
||||
|
||||
let[@inline] fetch_and_add r x =
|
||||
let v = r.x in
|
||||
r.x <- x + r.x;
|
||||
v
|
||||
|
||||
let[@inline] incr r = r.x <- 1 + r.x
|
||||
let[@inline] decr r = r.x <- r.x - 1
|
||||
|}
|
||||
|
||||
let atomic_after_412 = {|include Atomic|}
|
||||
|
||||
let write_file file s =
|
||||
let oc = open_out file in
|
||||
output_string oc s;
|
||||
close_out oc
|
||||
|
||||
let () =
|
||||
let version = Scanf.sscanf Sys.ocaml_version "%d.%d.%s" (fun x y _ -> x, y) in
|
||||
print_endline
|
||||
(if version >= (4, 12) then
|
||||
atomic_after_412
|
||||
else
|
||||
atomic_before_412);
|
||||
()
|
||||
Loading…
Add table
Reference in a new issue