Skip to content

Commit

Permalink
Apply review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrm committed Jul 4, 2024
1 parent c8c980d commit e7f16b2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
5 changes: 1 addition & 4 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,5 @@
(depends
(ocaml
(>= 4.12.0))
;; Test dependencies
(multicore-magic
(>= 2.2.0))
(dscheck
(= dev))))
(>= 0.5.0))))
3 changes: 1 addition & 2 deletions multicore-magic-dscheck.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ bug-reports: "https://github.com/ocaml-multicore/multicore-magic/issues"
depends: [
"dune" {>= "3.14"}
"ocaml" {>= "4.12.0"}
"multicore-magic" {>= "2.2.0"}
"dscheck" {= "dev"}
"dscheck" {>= "0.5.0"}
"odoc" {with-doc}
]
build: [
Expand Down
2 changes: 1 addition & 1 deletion src/dscheck/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name multicore_magic_dscheck)
(public_name multicore-magic-dscheck)
(libraries multicore-magic dscheck)
(libraries dscheck)
(enabled_if
(>= %{ocaml_version} 5)))
20 changes: 7 additions & 13 deletions src/dscheck/multicore_magic.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Atomic = Dscheck.TracedAtomic

let copy_as_padded = Fun.id
let copy_as ?padded:_ x = x
let make_padded_array = Array.make
let length_of_padded_array = Array.length
let length_of_padded_array_minus_1 xs = Array.length xs - 1
Expand All @@ -13,29 +14,22 @@ module Transparent_atomic = struct
let fenceless_set = set
end

let[@inline] fenceless_get (atomic : 'a Atomic.t) =
!(Sys.opaque_identity (Obj.magic atomic : 'a ref))

let[@inline] fenceless_set (atomic : 'a Atomic.t) value =
(Obj.magic atomic : 'a ref) := value

let fenceless_get = Atomic.get
let fenceless_set = Atomic.set
let[@inline] fence atomic = Atomic.fetch_and_add atomic 0 |> ignore

module Atomic_array = struct
type 'a t = 'a Atomic.t array

let[@inline] at (type a) (xs : a t) i : a Atomic.t =
(* ['a t] does not contain [float]s. *)
Obj.magic (Array.unsafe_get (Obj.magic xs : a ref array) i)

let[@inline] at (xs : 'a t) i : 'a Atomic.t = Array.get xs i
let[@inline] make n v = Array.init n @@ fun _ -> Atomic.make v
let[@inline] init n fn = Array.init n @@ fun i -> Atomic.make (fn i)
let[@inline] of_array xs = init (Array.length xs) (Array.unsafe_get xs)
let[@inline] of_array xs = init (Array.length xs) (Array.get xs)

external length : 'a array -> int = "%array_length"

let[@inline] unsafe_fenceless_set xs i v = Obj.magic (at xs i) := v
let[@inline] unsafe_fenceless_get xs i = !(Obj.magic (at xs i))
let unsafe_fenceless_set xs i v = Atomic.set xs.(i) v
let unsafe_fenceless_get xs i = Atomic.get xs.(i)

let[@inline] unsafe_compare_and_set xs i b a =
Atomic.compare_and_set (at xs i) b a
Expand Down
1 change: 1 addition & 0 deletions src/dscheck/multicore_magic.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Atomic = Dscheck.TracedAtomic

val copy_as_padded : 'a -> 'a
val copy_as : ?padded:bool -> 'a -> 'a
val make_padded_array : int -> 'a -> 'a array
val length_of_padded_array : 'a array -> int
val length_of_padded_array_minus_1 : 'a array -> int
Expand Down

0 comments on commit e7f16b2

Please sign in to comment.