default reactor

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-10-30 14:07:28 +01:00
parent 9ebd1972eb
commit 0e1eba91ce

View File

@ -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<Arc<Reactor>> = None;
pub fn default() -> Arc<Reactor> {
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<Epoll>,
removed: Mutex<Vec<Box<RegistrationInner>>>,