diff options
author | Enrico Tassi <Enrico.Tassi@inria.fr> | 2014-11-24 14:56:51 +0100 |
---|---|---|
committer | Enrico Tassi <Enrico.Tassi@inria.fr> | 2014-11-27 16:06:54 +0100 |
commit | 5f7234edcf0a6bef995c8d1dc31f679799a98557 (patch) | |
tree | 4d2b3f8c20f2f552bef4b60696e385837bf67918 /stm/workerPool.mli | |
parent | d86dbc9b9f4fbabd922b07e7c695f03cf6c03c43 (diff) |
WorkerPool: API to move a worker from an active pool to a parking one
This lets me have a pool of active workers of a fixed size,
plus a parking area where workers that completed their job
can stay holding their state (and eventually one can ask them
to query such state afterwards).
Diffstat (limited to 'stm/workerPool.mli')
-rw-r--r-- | stm/workerPool.mli | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/stm/workerPool.mli b/stm/workerPool.mli index 4e5512a4b..29398cc06 100644 --- a/stm/workerPool.mli +++ b/stm/workerPool.mli @@ -6,30 +6,50 @@ (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) -module Make(Worker : sig +type worker_id = string +type 'a spawn = + args:string array -> env:string array -> unit -> in_channel * out_channel * 'a +type active +type parking + +(* this shall come from a Spawn.* model *) +module type WorkerModel = sig type process val spawn : - ?prefer_sock:bool -> ?env:string array -> string -> string array -> + ?prefer_sock:bool -> ?env:string array -> string -> string array -> process * in_channel * out_channel -end) : sig +end -type worker_id = string -type spawn = - args:string array -> env:string array -> unit -> - in_channel * out_channel * Worker.process - -val init : - size:int -> - manager:(cancel:bool ref -> die:bool ref -> worker_id -> spawn -> unit) -> - (int -> worker_id) -> unit -val destroy : unit -> unit - -val is_empty : unit -> bool -val n_workers : unit -> int -val cancel : worker_id -> unit -val cancel_all : unit -> unit - -(* The worker should call this function *) -val worker_handshake : in_channel -> out_channel -> unit +(* this defines the main loop of the manager *) +module type ManagerModel = sig + type process + type extra (* extra stuff to pass to the manager *) + val manager : + extra -> cancel:bool ref -> die:bool ref -> worker_id -> process spawn -> + unit + val naming : int -> worker_id +end + +module Make(Worker : WorkerModel) + (Manager : ManagerModel with type process = Worker.process) : sig + + type 'a pool + + val create_active : Manager.extra -> int -> active pool + val create_parking : unit -> parking pool + + val is_empty : 'a pool -> bool + val n_workers : 'a pool -> int + + (* cancel signal *) + val cancel : 'a pool -> worker_id -> unit + val cancel_all : 'a pool -> unit + (* die signal + true removal, the pool is empty afterward *) + val destroy : 'a pool -> unit + + val move : active pool -> parking pool -> worker_id -> unit + + (* The worker should call this function *) + val worker_handshake : in_channel -> out_channel -> unit end |