From 0e1eba91ce57b37424ae0ef83e614d221e557603 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 30 Oct 2019 14:07:28 +0100 Subject: [PATCH] default reactor Signed-off-by: Wolfgang Bumiller --- src/reactor.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/reactor.rs b/src/reactor.rs index 2bb5b60..6798af2 100644 --- a/src/reactor.rs +++ b/src/reactor.rs @@ -2,7 +2,7 @@ use std::convert::TryFrom; use std::io; use std::os::unix::io::{AsRawFd, RawFd}; use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, Mutex, Once}; use std::task::{Context, Poll, Waker}; use std::thread::JoinHandle; @@ -11,6 +11,17 @@ use crate::error::io_err_other; use crate::poll_fn::poll_fn; use crate::tools::Fd; +static START: Once = Once::new(); +static mut REACTOR: Option> = None; + +pub fn default() -> Arc { + START.call_once(|| unsafe { + let reactor = Reactor::new().expect("setup main epoll reactor"); + REACTOR = Some(reactor); + }); + unsafe { Arc::clone(REACTOR.as_ref().unwrap()) } +} + pub struct Reactor { epoll: Arc, removed: Mutex>>,