Skip to content

Commit 065c596

Browse files
committed
refactor(clippy): fix clippy warnings
1 parent eea0f9b commit 065c596

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/pyroscope.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,9 @@ impl PyroscopeAgent {
278278

279279
// set running to true
280280
let pair = Arc::clone(&self.running);
281-
let (lock, cvar) = &*pair;
281+
let (lock, _cvar) = &*pair;
282282
let mut running = lock.lock()?;
283283
*running = true;
284-
drop(lock);
285-
drop(cvar);
286284
drop(running);
287285

288286
let (tx, rx): (Sender<u64>, Receiver<u64>) = channel();

src/timer/epoll.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ impl Timer {
6464
// Iterate through Senders
6565
txs.lock()?.iter().for_each(|tx| {
6666
// Send event to attached Sender
67-
match tx.send(current) {
68-
Ok(_) => {}
69-
Err(_) => {}
70-
}
67+
if tx.send(current).is_ok() {}
7168
});
7269
}
7370
}));
@@ -151,12 +148,16 @@ impl Timer {
151148
let mut events = Vec::with_capacity(1);
152149

153150
// wait for the timer to fire an event. This is function will block.
154-
epoll_wait(epoll_fd, events.as_mut_ptr(), 1, -1)?;
151+
unsafe {
152+
epoll_wait(epoll_fd, events.as_mut_ptr(), 1, -1)?;
153+
}
155154

156155
// read the value from the timerfd. This is required to re-arm the timer.
157156
let mut buffer: u64 = 0;
158157
let bufptr: *mut _ = &mut buffer;
159-
read(timer_fd, bufptr as *mut libc::c_void, 8)?;
158+
unsafe {
159+
read(timer_fd, bufptr as *mut libc::c_void, 8)?;
160+
}
160161

161162
Ok(())
162163
}
@@ -217,15 +218,21 @@ pub fn epoll_ctl(
217218
}
218219

219220
/// libc::epoll_wait wrapper
220-
pub fn epoll_wait(
221+
///
222+
/// # Safety
223+
/// This function is a wrapper for libc::epoll_wait.
224+
pub unsafe fn epoll_wait(
221225
epoll_fd: i32, events: *mut libc::epoll_event, maxevents: libc::c_int, timeout: libc::c_int,
222226
) -> Result<()> {
223-
check_err(unsafe { libc::epoll_wait(epoll_fd, events, maxevents, timeout) })?;
227+
check_err(libc::epoll_wait(epoll_fd, events, maxevents, timeout))?;
224228
Ok(())
225229
}
226230

227231
/// libc::read wrapper
228-
pub fn read(timer_fd: i32, bufptr: *mut libc::c_void, count: libc::size_t) -> Result<()> {
229-
check_err(unsafe { libc::read(timer_fd, bufptr, count) })?;
232+
///
233+
/// # Safety
234+
/// This function is a wrapper for libc::read.
235+
pub unsafe fn read(timer_fd: i32, bufptr: *mut libc::c_void, count: libc::size_t) -> Result<()> {
236+
check_err(libc::read(timer_fd, bufptr, count))?;
230237
Ok(())
231238
}

tests/timer-epoll.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ mod tests {
7878
let mut events = vec![libc::epoll_event { events: 0, u64: 0 }];
7979

8080
// Expire in 1ms
81-
let void = epoll_wait(epoll_fd, events.as_mut_ptr(), 1, 1).unwrap();
81+
let void = unsafe {
82+
epoll_wait(epoll_fd, events.as_mut_ptr(), 1, 1).unwrap();
83+
};
8284

8385
assert!(void == ());
8486
}

0 commit comments

Comments
 (0)