Skip to content

Commit ff89cda

Browse files
committed
initial version
0 parents  commit ff89cda

19 files changed

+1182
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_build
2+
verdi-runtime.install

CHANGES.md

Whitespace-only changes.

LICENSE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2014-2017, Verdi Team
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
8+
1. Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Verdi framework runtime library

_tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
true : bin_annot

opam

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
opam-version: "1.2"
2+
version: "1.0"
3+
maintainer: "[email protected]"
4+
homepage: "https://github.com/DistributedComponents/verdi-runtime"
5+
dev-repo: "https://github.com/DistributedComponents/verdi-runtime.git"
6+
bug-reports: "https://github.com/DistributedComponents/verdi-runtime/issues"
7+
authors: ["James Wilcox <>" "Doug Woos <>" "Steve Anton <>" "Karl Palmskog <>" "Ryan Doenges <>"]
8+
available: [ ocaml-version >= "4.02.3"]
9+
license: "BSD"
10+
depends: [
11+
"ocamlfind" {build}
12+
"ocamlbuild" {build}
13+
"topkg" {build} ]
14+
build: [
15+
"ocaml" "pkg/pkg.ml" "build"
16+
"--pinned" "%{pinned}%"
17+
]

pkg/META

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version = "%%VERSION%%"
2+
description = "Verdi framework runtime library"
3+
requires = "unix str"
4+
archive(byte) = "verdi_runtime.cma"
5+
archive(byte, plugin) = "verdi_runtime.cma"
6+
archive(native) = "verdi_runtime.cmxa"
7+
archive(native, plugin) = "verdi_runtime.cmxs"
8+
exists_if = "verdi_runtime.cma"

pkg/pkg.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env ocaml
2+
#use "topfind";;
3+
#require "topkg"
4+
open Topkg
5+
6+
let () =
7+
Pkg.describe "verdi-runtime" @@ fun c ->
8+
Ok [ Pkg.lib "src/Util.cmi";
9+
Pkg.lib "src/Opts.cmi";
10+
Pkg.lib "src/Daemon.cmi";
11+
Pkg.lib "src/Shim.cmi";
12+
Pkg.lib "src/OrderedShim.cmi";
13+
Pkg.lib "src/verdi_runtime.a";
14+
Pkg.lib "src/verdi_runtime.cma";
15+
Pkg.lib "src/verdi_runtime.cmxa";
16+
Pkg.lib "src/verdi_runtime.cmxs" ]

src/Daemon.ml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
type ('env, 'state) task =
2+
{ fd : Unix.file_descr
3+
; mutable select_on : bool
4+
; mutable wake_time : float option
5+
; mutable process_read : ('env, 'state) task -> 'env -> 'state -> bool * ('env, 'state) task list * 'state
6+
; mutable process_wake : ('env, 'state) task -> 'env -> 'state -> bool * ('env, 'state) task list * 'state
7+
; finalize : ('env, 'state) task -> 'env -> 'state -> 'state
8+
}
9+
10+
let process process_f t hts env state =
11+
let state = ref state in
12+
let (finished, ts, state') = process_f t env !state in
13+
state := state';
14+
if finished then begin
15+
Hashtbl.remove hts t.fd;
16+
state := t.finalize t env !state
17+
end;
18+
List.iter (fun t' -> Hashtbl.add hts t'.fd t') ts;
19+
!state
20+
21+
let rec eloop default_timeout old_timestamp hts env state =
22+
let state = ref state in
23+
let (select_fds, min_timeout) =
24+
Hashtbl.fold
25+
(fun fd t (fds, timeout) ->
26+
let fds' = if t.select_on then fd :: fds else fds in
27+
let timeout' =
28+
match t.wake_time with
29+
| None -> timeout
30+
| Some wake_time -> min timeout wake_time
31+
in (fds', timeout'))
32+
hts ([], default_timeout) in
33+
let (ready_fds, _, _) = Util.select_unintr select_fds [] [] min_timeout in
34+
List.iter
35+
(fun fd ->
36+
let t = Hashtbl.find hts fd in
37+
state := process t.process_read t hts env !state) ready_fds;
38+
let new_timestamp = Unix.gettimeofday () in
39+
let elapsed_time = new_timestamp -. old_timestamp in
40+
let wake_tasks =
41+
Hashtbl.fold
42+
(fun fd t ts ->
43+
match t.wake_time with
44+
| None -> ts
45+
| Some wake_time ->
46+
if elapsed_time >= wake_time then
47+
t :: ts
48+
else
49+
(t.wake_time <- Some (wake_time -. elapsed_time); ts))
50+
hts [] in
51+
List.iter (fun t -> state := process t.process_wake t hts env !state) wake_tasks;
52+
eloop default_timeout new_timestamp hts env !state

src/Daemon.mli

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type ('env, 'state) task =
2+
{ fd : Unix.file_descr
3+
; mutable select_on : bool
4+
; mutable wake_time : float option
5+
; mutable process_read : ('env, 'state) task -> 'env -> 'state -> bool * ('env, 'state) task list * 'state
6+
; mutable process_wake : ('env, 'state) task -> 'env -> 'state -> bool * ('env, 'state) task list * 'state
7+
; finalize : ('env, 'state) task -> 'env -> 'state -> 'state
8+
}
9+
10+
val eloop : float -> float -> (Unix.file_descr, ('a, 'b) task) Hashtbl.t -> 'a -> 'b -> 'c

0 commit comments

Comments
 (0)