Skip to content

Commit

Permalink
Bump saturn. (#4105)
Browse files Browse the repository at this point in the history
  • Loading branch information
toots authored Dec 15, 2024
1 parent 95fb55b commit 3d6d2d9
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/opam/liquidsoap-core-windows.opam
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ depends: [
"mm-windows" {>= "0.8.4"}
"re-windows" {>= "1.11.0"}
"cry-windows" {>= "1.0.1"}
"saturn_lockfree-windows" {>= "0.4.1" & < "0.5.0"}
"saturn_lockfree-windows" {>= "0.5.0"}
"sedlex" {>= "3.2"}
"sedlex-windows" {>= "3.2"}
"magic-mime-windows"
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/build-posix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cd ..

opam update
opam remove -y jemalloc
opam install -y tls.1.0.2 ca-certs mirage-crypto-rng cstruct saturn_lockfree.0.4.1 ppx_hash memtrace
opam install -y tls.1.0.2 ca-certs mirage-crypto-rng cstruct saturn_lockfree.0.5.0 ppx_hash memtrace

cd /tmp/liquidsoap-full

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
cp PACKAGES.minimal PACKAGES
opam update
opam pin -yn .
opam install -y saturn_lockfree.0.4.1 ppx_hash
opam install -y saturn_lockfree.0.5.0 ppx_hash
opam info -f "depopts:" liquidsoap-core | grep -v osx-secure-transport | xargs opam remove -y inotify ffmpeg-avutil cohttp-lwt-unix prometheus-app ${{ needs.build_details.outputs.minimal_exclude_deps }}
opam install -y mem_usage
echo "::endgroup::"
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
cd /tmp/liquidsoap-full/liquidsoap
eval "$(opam config env)"
opam update
opam install -y xml-light
opam install -y xml-light saturn_lockfree.0.5.0
dune build --profile release ./src/js/interactive_js.bc.js
tree_sitter_parse:
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
(depends
(ocaml (>= 4.14))
dune-site
(saturn_lockfree (and (>= 0.4.1) (< 0.5.0)))
(saturn_lockfree (>= 0.5.0))
(re (>= 1.11.0))
(ppx_string :build)
(ppx_hash :build)
Expand Down
2 changes: 1 addition & 1 deletion liquidsoap-lang.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ depends: [
"dune" {>= "3.6"}
"ocaml" {>= "4.14"}
"dune-site"
"saturn_lockfree" {>= "0.4.1" & < "0.5.0"}
"saturn_lockfree" {>= "0.5.0"}
"re" {>= "1.11.0"}
"ppx_string" {build}
"ppx_hash" {build}
Expand Down
50 changes: 20 additions & 30 deletions src/lang/queues.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,32 @@ module Queue = struct

let flush_elements q =
let rec flush_elements_f elements =
try flush_elements_f (pop q :: elements) with Empty -> List.rev elements
match pop_exn q with
| el -> flush_elements_f (el :: elements)
| exception Empty -> List.rev elements
in
flush_elements_f []

let pop q = try pop q with Empty -> raise Not_found
let pop q = try pop_exn q with Empty -> raise Not_found
let peek q = try peek_exn q with Empty -> raise Not_found
let flush_iter q fn = List.iter fn (flush_elements q)

let flush_fold q fn ret =
let flush_fold_f ret el = fn el ret in
List.fold_left flush_fold_f ret (flush_elements q)

let elements q =
let rec elements_f l cursor =
match next cursor with
| Some (el, cursor) -> elements_f (el :: l) cursor
| None -> List.rev l
let rec elements_f l =
match pop_exn q with
| el -> elements_f (el :: l)
| exception Empty -> List.rev l
in
elements_f [] (snapshot q)

let exists q fn =
let rec exists_f l cursor =
match next cursor with
| Some (el, _) when fn el -> true
| Some (el, cursor) -> exists_f (el :: l) cursor
| None -> false
in
exists_f [] (snapshot q)

let length q =
let rec length_f pos cursor =
match next cursor with
| Some (_, cursor) -> length_f (pos + 1) cursor
| None -> pos
in
length_f 0 (snapshot q)
let elements = elements_f [] in
List.iter (push q) elements;
elements

let exists q fn = List.exists fn (elements q)
let length q = List.length (elements q)
let iter q fn = List.iter fn (elements q)
let fold q fn v = List.fold_left (fun v e -> fn e v) v (elements q)

Expand Down Expand Up @@ -129,16 +119,16 @@ module WeakQueue = struct
let fold q fn v = List.fold_left (fun v e -> fn e v) v (elements q)

let filter q fn =
let rec filter_f cursor =
match next cursor with
| Some (el, cursor) ->
let rec filter_f () =
match pop_exn q with
| el ->
for i = 0 to Weak.length el - 1 do
match Weak.get el i with
| Some p when fn p -> ()
| _ -> Weak.set el i None
done;
filter_f cursor
| None -> ()
filter_f ()
| exception Empty -> ()
in
filter_f (snapshot q)
filter_f ()
end
6 changes: 6 additions & 0 deletions src/lang/queues.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*****************************************************************************)

(** Note: these queues a lock-free and not intended to hold large number
of values. *)

module Queue : sig
type 'a t

Expand All @@ -31,7 +34,10 @@ module Queue : sig
val pop : 'a t -> 'a

val pop_opt : 'a t -> 'a option

(** Raises [Not_found] when no element can be found. *)
val peek : 'a t -> 'a

val peek_opt : 'a t -> 'a option
val flush_iter : 'a t -> ('a -> unit) -> unit
val flush_fold : 'a t -> ('a -> 'b -> 'b) -> 'b -> 'b
Expand Down

0 comments on commit 3d6d2d9

Please sign in to comment.