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
15 changes: 8 additions & 7 deletions lib/domainpc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ let cpus_per_core =
in
match IntMap.to_list m with
| [] -> failwith "unexpected: no CPUS/Cores found"
| (_, cpus) :: tl ->
(* set the cpus on which the parent thread can run, the other cpus
are put in a queue to be used by child domains. *)
Processor.Affinity.set_ids cpus;
List.iter (fun (_, cpus) -> Queue.add cpus queue) tl;
| l ->
List.iter (fun (_, cpus) -> Queue.add cpus queue) l;
queue

(** fetches a set of cpus, if all sets of cpus are used by other domains, either
Expand Down Expand Up @@ -62,7 +59,7 @@ let spawn f =
let cpus = get_cpus () in
spawn_aux f cpus)

let spawn_n ?n f =
let spawn_n ?n ~before_spawn f =
let cpul =
Mutex.protect cores_mutex (fun () ->
let ncores = Queue.length cpus_per_core in
Expand All @@ -80,4 +77,8 @@ let spawn_n ?n f =
ncores))
in
Array.of_list
(List.map (fun cpus -> Domain.spawn (fun () -> spawn_aux f cpus)) cpul)
(List.map
(fun cpus ->
before_spawn ();
Domain.spawn (fun () -> spawn_aux f cpus))
cpul)
3 changes: 2 additions & 1 deletion lib/domainpc.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ val wait_on_unavailable : unit -> unit
(** [wait_on_unavailable ()] when all cores are used, wait for one of them to be
freed instead of crashing. *)

val spawn_n : ?n:int -> (unit -> 'a) -> 'a t array
val spawn_n :
?n:int -> before_spawn:(unit -> unit) -> (unit -> 'a) -> 'a t array
(** [spawn_n ?n f] if [n] is provided and is less than or equal to the number of
free physical cores, spwans [n] new domains. If [n] is not provided and
there is at least one free physical core, spawns as many domains as there
Expand Down