orx_parallel/executor/thread_executor.rs
1use orx_concurrent_iter::ConcurrentIter;
2
3/// Thread executor responsible for executing the tasks assigned to the thread by the
4/// parallel executor.
5pub trait ThreadExecutor: Sized {
6 /// Type of the shared state among threads.
7 type SharedState;
8
9 /// Returns the next chunks size to be pulled from the input `iter` for the given
10 /// current `shared_state`.
11 fn next_chunk_size<I>(&self, shared_state: &Self::SharedState, iter: &I) -> usize
12 where
13 I: ConcurrentIter;
14
15 /// Hook that will be called before starting to execute the chunk of the given `chunk_size`.
16 fn begin_chunk(&mut self, chunk_size: usize);
17
18 /// Hook that will be called after completing the chunk of the given `chunk_size`.
19 /// The `shared_state` is also provided so that it can be updated to send information to the
20 /// parallel executor and other thread executors.
21 fn complete_chunk(&mut self, shared_state: &Self::SharedState, chunk_size: usize);
22
23 /// Hook that will be called after completing the task.
24 /// The `shared_state` is also provided so that it can be updated to send information to the
25 /// parallel executor and other thread executors.
26 fn complete_task(&mut self, shared_state: &Self::SharedState);
27}