forked from cil-project/cil
-
Notifications
You must be signed in to change notification settings - Fork 21
Replace dependency on domain_shims
with lightweight DLS shim for single-threaded OCaml
#186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,6 @@ depends: [ | |
"conf-perl" | ||
"cppo" | ||
"conf-gcc" | ||
"domain_shims" | ||
] | ||
conflicts: ["cil"] | ||
build: [ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
v | ||
|
||
let set k v = | ||
k.value <- Some v | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 thisget
(!) 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.