Skip to content

Commit

Permalink
Updated POOL to use a "static mut" instead of using "lazy_static" and…
Browse files Browse the repository at this point in the history
… a QrwLock, fixing some (random) panics from the threadpool that would freeze the system.

Signed-off-by: Matthieu Le brazidec <matthieu@lebrazidec.email>
  • Loading branch information
r3v2d0g committed Nov 7, 2019
1 parent c0e1f27 commit a760987
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bastion/src/system.rs
Expand Up @@ -12,17 +12,20 @@ use qutex::{QrwLock, Qutex};
use std::task::Poll;
use threadpool::ThreadPool;

// FIXME: unsafe?
static mut POOL: Option<ThreadPool> = None;

pub(crate) fn schedule(proc: LightProc) {
// FIXME: panics?
let pool = POOL.clone().read().wait().unwrap();
pool.execute(|| proc.run())
// FIXME unsafe?
let pool = unsafe { POOL.clone().unwrap() };
pool.execute(|| proc.run());
}

lazy_static! {
pub(crate) static ref SYSTEM: Qutex<Option<ProcHandle<()>>> = Qutex::new(None);
pub(crate) static ref SYSTEM_SENDER: Sender = System::init();
pub(crate) static ref ROOT_SPV: QrwLock<Option<SupervisorRef>> = QrwLock::new(None);
pub(crate) static ref POOL: QrwLock<ThreadPool> = QrwLock::new(ThreadPool::default());
}

#[derive(Debug)]
Expand All @@ -38,6 +41,9 @@ pub(crate) struct System {

impl System {
pub(crate) fn init() -> Sender {
// FIXME unsafe?
unsafe { POOL = Some(ThreadPool::default()) };

let parent = Parent::none();
let bcast = Broadcast::with_id(parent, NIL_ID);
let launched = FxHashMap::default();
Expand Down

0 comments on commit a760987

Please sign in to comment.