Skip to content

Commit f759478

Browse files
committed
imp(cfg): separate timer implementations
1 parent 05f7af1 commit f759478

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

src/timer/epoll.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2021 Developers of Pyroscope.
2+
3+
// Licensed under the Apache License, Version 2.0 <LICENSE or
4+
// https://www.apache.org/licenses/LICENSE-2.0>. This file may not be copied, modified, or distributed
5+
// except according to those terms.
6+
7+
use crate::Result;
8+
9+
use std::sync::{mpsc::Sender, Arc, Mutex};
10+
use std::{thread, thread::JoinHandle};
11+
12+
#[derive(Debug, Default)]
13+
pub struct Timer {
14+
/// A vector to store listeners (mpsc::Sender)
15+
txs: Arc<Mutex<Vec<Sender<u64>>>>,
16+
17+
/// Thread handle
18+
pub handle: Option<JoinHandle<Result<()>>>,
19+
}
20+
21+
impl Timer {
22+
pub fn initialize(self) -> Self {
23+
self
24+
}
25+
26+
pub fn attach_listener(&mut self, tx: Sender<u64>) -> Result<()> {
27+
Ok(())
28+
}
29+
30+
pub fn drop_listeners(&mut self) -> Result<()> {
31+
Ok(())
32+
}
33+
}

src/timer/kqueue.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2021 Developers of Pyroscope.
2+
3+
// Licensed under the Apache License, Version 2.0 <LICENSE or
4+
// https://www.apache.org/licenses/LICENSE-2.0>. This file may not be copied, modified, or distributed
5+
// except according to those terms.
6+
7+
use crate::Result;
8+
9+
use std::sync::{mpsc::Sender, Arc, Mutex};
10+
use std::{thread, thread::JoinHandle};
11+
12+
#[derive(Debug, Default)]
13+
pub struct Timer {
14+
/// A vector to store listeners (mpsc::Sender)
15+
txs: Arc<Mutex<Vec<Sender<u64>>>>,
16+
17+
/// Thread handle
18+
pub handle: Option<JoinHandle<Result<()>>>,
19+
}
20+
21+
impl Timer {
22+
pub fn initialize(self) -> Self {
23+
self
24+
}
25+
26+
pub fn attach_listener(&mut self, tx: Sender<u64>) -> Result<()> {
27+
Ok(())
28+
}
29+
30+
pub fn drop_listeners(&mut self) -> Result<()> {
31+
Ok(())
32+
}
33+
}

src/timer/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2021 Developers of Pyroscope.
2+
3+
// Licensed under the Apache License, Version 2.0 <LICENSE or
4+
// https://www.apache.org/licenses/LICENSE-2.0>. This file may not be copied, modified, or distributed
5+
// except according to those terms.
6+
7+
// Possibly: ios, netbsd, openbsd, freebsd
8+
#[cfg(target_os = "macos")]
9+
pub mod kqueue;
10+
#[cfg(target_os = "macos")]
11+
pub use kqueue::Timer;
12+
13+
// Possibly: android
14+
#[cfg(target_os = "linux")]
15+
pub mod epoll;
16+
#[cfg(target_os = "linux")]
17+
pub use epoll::Timer;
18+
19+
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
20+
pub mod sleep;
21+
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
22+
pub use sleep::Timer;
File renamed without changes.

0 commit comments

Comments
 (0)