]>
Commit | Line | Data |
---|---|---|
8962159b | 1 | use std::io; |
df560c25 | 2 | use std::os::unix::io::RawFd; |
8962159b WB |
3 | use std::sync::{mpsc, Arc}; |
4 | use std::thread::JoinHandle; | |
5 | ||
6 | use crate::epoll::Epoll; | |
7 | ||
8 | pub struct AssertSync<T>(pub T); | |
9 | unsafe impl<T> Sync for AssertSync<T> {} | |
10 | ||
11 | pub struct Reactor { | |
12 | epoll: Arc<Epoll>, | |
13 | removals: AssertSync<mpsc::Sender<RawFd>>, | |
14 | thread: JoinHandle<()>, | |
15 | } | |
16 | ||
17 | impl Reactor { | |
df560c25 | 18 | pub fn new() -> io::Result<Self> { |
8962159b WB |
19 | let epoll = Arc::new(Epoll::new()?); |
20 | ||
21 | let (send_remove, recv_remove) = mpsc::channel(); | |
22 | ||
23 | let handle = std::thread::spawn({ | |
24 | let epoll = Arc::clone(&epoll); | |
25 | move || Self::thread_main(epoll, recv_remove) | |
26 | }); | |
27 | ||
28 | Ok(Self { | |
29 | epoll, | |
30 | removals: AssertSync(send_remove), | |
31 | thread: handle, | |
32 | }) | |
33 | } | |
34 | ||
35 | fn thread_main(epoll: Arc<Epoll>, removals: mpsc::Receiver<RawFd>) { | |
36 | let _ = epoll; | |
37 | let _ = removals; | |
d1b1deab WB |
38 | loop { |
39 | } | |
8962159b WB |
40 | } |
41 | } |