rumtk_web/utils/jobs.rs
1/*
2 * rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
3 * This toolkit aims to be reliable, simple, performant, and standards compliant.
4 * Copyright (C) 2025 Luis M. Santos, M.D.
5 * Copyright (C) 2025 Nick Stephenson
6 * Copyright (C) 2025 Ethan Dixon
7 * Copyright (C) 2025 MedicalMasses L.L.C.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23use rumtk_core::core::RUMResult;
24use rumtk_core::threading::threading_manager::{TaskID, TaskManager};
25use rumtk_core::types::RUMBuffer;
26
27pub type JobID = TaskID;
28pub type JobBuffer = RUMBuffer;
29type JobManager = TaskManager<JobBuffer>;
30
31static mut TASK_MANAGER: Option<JobManager> = None;
32
33pub fn init_job_manager(workers: &usize) -> RUMResult<()> {
34 let manager = TaskManager::<JobBuffer>::new(workers)?;
35 unsafe {
36 TASK_MANAGER = Some(manager);
37 }
38 Ok(())
39}
40
41pub fn get_manager() -> &'static mut JobManager {
42 let mut manager = unsafe { TASK_MANAGER.as_mut().unwrap() };
43 manager
44}
45
46#[macro_export]
47macro_rules! rumtk_web_init_job_manager {
48 ( $workers:expr ) => {{
49 use $crate::jobs::init_job_manager;
50 init_job_manager($workers)
51 }};
52}
53
54#[macro_export]
55macro_rules! rumtk_web_get_job_manager {
56 ( ) => {{
57 use $crate::jobs::get_manager;
58 get_manager()
59 }};
60}