Skip to content

Commit

Permalink
remove deprecated use of Lwt_sequence and other warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
avsm committed Jan 14, 2019
1 parent 2db0c8a commit f61c96c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Port build from jbuilder to Dune (@avsm).
* Update opam metadata to the 2.0 format (@avsm).
* Removed deprecated use of `Lwt_sequence` and depend
on the equivalent `lwt-dllist` package instead (@avsm)

## 3.0.1 (2018-07-09)

Expand Down
2 changes: 2 additions & 0 deletions lib/console_ring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

[@@@warning "-32"]

open Ring

module Ring = struct
Expand Down
8 changes: 3 additions & 5 deletions lib/ring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

open Printf

type buf = Cstruct.t

let sub t off len = Cstruct.sub t off len
Expand Down Expand Up @@ -120,7 +118,7 @@ module Rpc = struct
unsafe_save_uint32 sring.buf _req_event req_event;
memory_barrier ()

let nr_ents sring = sring.nr_ents
let _nr_ents sring = sring.nr_ents

let slot sring idx =
(* TODO should precalculate these and store in the sring? this is fast-path *)
Expand All @@ -147,7 +145,7 @@ module Rpc = struct
let get_free_requests t =
t.sring.nr_ents - (t.req_prod_pvt - t.rsp_cons)

let is_ring_full t =
let _is_ring_full t =
get_free_requests t = 0

let has_unconsumed_responses t =
Expand Down Expand Up @@ -247,7 +245,7 @@ module Rpc = struct
t.rsp_prod_pvt <- t.rsp_prod_pvt + 1;
s

let next_slot t =
let _next_slot t =
slot t (next_res_id t)

let final_check_for_requests t =
Expand Down
2 changes: 1 addition & 1 deletion lib/xenstore_ring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

[@@@warning "-32"]
open Ring

module Ring = struct
type t = buf
let of_buf t = t
module Layout = struct
(* memory layout from the frontend's point of view *)
Expand Down
2 changes: 1 addition & 1 deletion lwt/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(library
(name lwt_shared_memory_ring)
(public_name shared-memory-ring-lwt)
(libraries shared-memory-ring lwt mirage-profile)
(libraries shared-memory-ring lwt lwt-dllist mirage-profile)
(wrapped false))
16 changes: 8 additions & 8 deletions lwt/lwt_ring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ module Front = struct
type ('a, 'b) t = {
ring: ('a, 'b) Ring.Rpc.Front.t;
wakers: ('b, 'a Lwt.u) Hashtbl.t; (* id * wakener *)
waiters: unit Lwt.u Lwt_sequence.t;
waiters: unit Lwt.u Lwt_dllist.t;
string_of_id: 'b -> string;
}

let init string_of_id ring =
let wakers = Hashtbl.create 7 in
let waiters = Lwt_sequence.create () in
let waiters = Lwt_dllist.create () in
{ ring; wakers; waiters; string_of_id }

let rec get_free_slot t =
if Ring.Rpc.Front.get_free_requests t.ring > 0 then
return (Ring.Rpc.Front.next_req_id t.ring)
else begin
let th, u = MProf.Trace.named_task "ring.get_free_slot" in
let node = Lwt_sequence.add_r u t.waiters in
Lwt.on_cancel th (fun _ -> Lwt_sequence.remove node);
let node = Lwt_dllist.add_r u t.waiters in
Lwt.on_cancel th (fun _ -> Lwt_dllist.remove node);
th >>= fun () ->
get_free_slot t
end
Expand All @@ -50,8 +50,8 @@ module Front = struct
else begin
assert (n <= Ring.Rpc.Front.nr_ents t.ring);
let th, u = MProf.Trace.named_task "ring.wait_for_free" in
let node = Lwt_sequence.add_r u t.waiters in
Lwt.on_cancel th (fun _ -> Lwt_sequence.remove node);
let node = Lwt_dllist.add_r u t.waiters in
Lwt.on_cancel th (fun _ -> Lwt_dllist.remove node);
th >>= fun () ->
wait_for_free t n
end
Expand All @@ -72,7 +72,7 @@ module Front = struct
(Hashtbl.fold (fun k _ acc -> k :: acc) t.wakers [])));
);
(* Check for any sleepers waiting for free space *)
match Lwt_sequence.take_opt_l t.waiters with
match Lwt_dllist.take_opt_l t.waiters with
|None -> ()
|Some u -> Lwt.wakeup u ()

Expand Down Expand Up @@ -109,7 +109,7 @@ module Front = struct
) t.wakers;
(* Check for any sleepers waiting for free space *)
let rec loop () =
match Lwt_sequence.take_opt_l t.waiters with
match Lwt_dllist.take_opt_l t.waiters with
| None -> ()
| Some u -> Lwt.wakeup_exn u Shutdown; loop ()
in loop ()
Expand Down
1 change: 1 addition & 0 deletions shared-memory-ring-lwt.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ depends: [
"ppx_cstruct"
"shared-memory-ring"
"lwt"
"lwt-dllist"
"mirage-profile"
"ounit" {with-test}
]
Expand Down

0 comments on commit f61c96c

Please sign in to comment.