Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ This is a fork of the 'cil' package used for 'goblint'. Major changes include:
conf-perl
cppo
conf-gcc
domain_shims
)
(conflicts cil) ; only because we both install the cilly executable
)
1 change: 0 additions & 1 deletion goblint-cil.opam
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ depends: [
"conf-perl"
"cppo"
"conf-gcc"
"domain_shims"
]
conflicts: ["cil"]
build: [
Expand Down
20 changes: 20 additions & 0 deletions src/domain.ocaml4.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module DLS = struct
type 'a key = {
mutable value: 'a option;
initialiser: unit -> 'a;
}

let new_key ?split_from_parent initialiser =
{ value = None; initialiser }

let get (k: 'a key) =
match k.value with
| Some v -> v
| None ->
let v = k.initialiser () in
k.value <- Some v;
Comment on lines +14 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this really works. There's a race condition here (yes, on OCaml 4 without threads!):
If the signal handler fires between these two lines to set something, then this get (!) will overwrite the "new" value with the initial one.

There's a good reason why domain_shims uses atomicity (although via a Dirk-style mutex). I think atomicity is inevitable in a correct solution: it's just that the atomicity probably should be proper, not using a mutex, possibly with a lock-free data structure.

v

let set k v =
k.value <- Some v
end
30 changes: 30 additions & 0 deletions src/domain.ocaml4.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module DLS : sig
(** Domain-local Storage *)

type 'a key
(** Type of a DLS key *)

val new_key : ?split_from_parent:('a -> 'a) -> (unit -> 'a) -> 'a key
(** [new_key f] returns a new key bound to initialiser [f] for accessing
domain-local variables.

If [split_from_parent] is provided, spawning a domain will derive the
child value (for this key) from the parent value.

Note that the [split_from_parent] call is computed in the parent
domain, and is always computed regardless of whether the child domain
will use it. If the splitting function is expensive or requires
client-side computation, consider using ['a Lazy.t key].
*)

val get : 'a key -> 'a
(** [get k] returns [v] if a value [v] is associated to the key [k] on
the calling domain's domain-local state. Sets [k]'s value with its
initialiser and returns it otherwise. *)

val set : 'a key -> 'a -> unit
(** [set k v] updates the calling domain's domain-local state to associate
the key [k] with value [v]. It overwrites any previous values associated
to [k], which cannot be restored later. *)

end
12 changes: 11 additions & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(library
(public_name goblint-cil)
(name goblintCil)
(libraries zarith unix str stdlib-shims domain_shims)
(libraries zarith unix str stdlib-shims)
(modules (:standard \ main mainFeature ciloptions machdepConfigure machdepArchConfigure modelConfigure))
)

Expand All @@ -16,6 +16,16 @@
(target machdep-config.h)
(action (run ./machdepConfigure.exe)))

(rule
(targets domain.ml domain.mli)
(deps domain.ocaml4.ml domain.ocaml4.mli)
(enabled_if (< %{ocaml_version} 5.0))
(action
(progn
(copy domain.ocaml4.ml domain.ml)
(copy domain.ocaml4.mli domain.mli)
)))

(rule
(deps machdep-config.h machdep-ml.c)
(target machdep-ml.exe)
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ else
endif

testrun/% : $(SMALL1)/%.ml
ocamlfind $(CAMLC) -I $(OBJDIR_DUNE) -I $(OBJDIR_MAKE) -package zarith -package domain_shims unix.$(CMXA) str.$(CMXA) zarith.$(CMXA) threads.$(CMXA) domain_shims.$(CMXA) -thread \
ocamlfind $(CAMLC) -I $(OBJDIR_DUNE) -I $(OBJDIR_MAKE) -package zarith unix.$(CMXA) str.$(CMXA) zarith.$(CMXA) threads.$(CMXA) -thread \
goblintCil.$(CMXA) \
$(EXEOUT) $(basename $<).exe $<
$(basename $<).exe
Expand Down
Loading