From deb96302e1139214d85ffe1932a72bc84c1b5cb0 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 13 Mar 2025 10:07:39 -0400 Subject: [PATCH] mli for worker loop --- src/core/worker_loop_.mli | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/core/worker_loop_.mli diff --git a/src/core/worker_loop_.mli b/src/core/worker_loop_.mli new file mode 100644 index 00000000..e5b0c969 --- /dev/null +++ b/src/core/worker_loop_.mli @@ -0,0 +1,37 @@ +(** Internal module that is used for workers. + + A thread pool should use this [worker_loop] to run tasks, + handle effects, etc. *) + +open Types_ + +type task_full = + | T_start of { + fiber: fiber; + f: unit -> unit; + } + | T_resume : { + fiber: fiber; + k: unit -> unit; + } + -> task_full + +val _dummy_task : task_full + +type around_task = + | AT_pair : (Runner.t -> 'a) * (Runner.t -> 'a -> unit) -> around_task + +exception No_more_tasks + +type 'st ops = { + schedule: 'st -> task_full -> unit; + get_next_task: 'st -> task_full; + get_thread_state: unit -> 'st; + around_task: 'st -> around_task; + on_exn: 'st -> Exn_bt.t -> unit; + runner: 'st -> Runner.t; + before_start: 'st -> unit; + cleanup: 'st -> unit; +} + +val worker_loop : block_signals:bool -> ops:'st ops -> 'st -> unit