diff --git a/src/lib.rs b/src/lib.rs index e01c026..e361e75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -605,10 +605,6 @@ impl HelperState { lock.consumer_done = true; self.cvar.notify_one(); } - - fn producer_done(&self) -> bool { - self.lock().producer_done - } } /// Finds and returns the value of `--jobserver-auth=` in the given diff --git a/src/unix.rs b/src/unix.rs index aed2813..2773e62 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -291,7 +291,7 @@ impl Client { { let read = self.read().as_raw_fd(); loop { - match non_blocking_read(read, &mut buf) { + match non_blocking_read(read, &buf) { Ok(1) => return Ok(Some(Acquired { byte: buf[0] })), Ok(_) => { return Err(io::Error::new( @@ -437,7 +437,7 @@ pub(crate) fn spawn_helper( })); } Err(e) => break f(Err(e)), - Ok(None) if helper.producer_done() => break, + Ok(None) if helper.lock().producer_done => break, Ok(None) => {} } }); @@ -625,12 +625,7 @@ mod test { use crate::{test::run_named_fifo_try_acquire_tests, Client}; - use std::{ - fs::File, - io::{self, Write}, - os::unix::io::AsRawFd, - sync::Arc, - }; + use std::sync::Arc; fn from_imp_client(imp: ClientImp) -> Client { Client { @@ -657,6 +652,12 @@ mod test { #[cfg(not(target_os = "linux"))] #[test] fn test_try_acquire_annoymous_pipe_linux_specific_optimization() { + use std::{ + fs::File, + io::{self, Write}, + os::unix::io::AsRawFd, + }; + let (read, write) = nix::unistd::pipe().unwrap(); let read = File::from(read); let mut write = File::from(write); diff --git a/src/windows.rs b/src/windows.rs index 997696c..7e6e6d4 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -15,9 +15,13 @@ pub struct Client { #[derive(Debug)] pub struct Acquired; +#[allow(clippy::upper_case_acronyms)] type BOOL = i32; +#[allow(clippy::upper_case_acronyms)] type DWORD = u32; +#[allow(clippy::upper_case_acronyms)] type HANDLE = *mut u8; +#[allow(clippy::upper_case_acronyms)] type LONG = i32; const ERROR_ALREADY_EXISTS: DWORD = 183; @@ -71,7 +75,7 @@ extern "system" { // randomness. fn getrandom(dest: &mut [u8]) -> io::Result<()> { // Prevent overflow of u32 - for chunk in dest.chunks_mut(u32::max_value() as usize) { + for chunk in dest.chunks_mut(u32::MAX as usize) { let ret = unsafe { RtlGenRandom(chunk.as_mut_ptr(), chunk.len() as u32) }; if ret == 0 { return Err(io::Error::new( @@ -115,10 +119,7 @@ impl Client { continue; } name.pop(); // chop off the trailing nul - let client = Client { - sem: handle, - name: name, - }; + let client = Client { sem: handle, name }; if create_limit != limit { client.acquire()?; } @@ -259,7 +260,7 @@ pub(crate) fn spawn_helper( state.for_each_request(|_| { const WAIT_OBJECT_1: u32 = WAIT_OBJECT_0 + 1; match unsafe { WaitForMultipleObjects(2, objects.as_ptr(), FALSE, INFINITE) } { - WAIT_OBJECT_0 => return, + WAIT_OBJECT_0 => {} WAIT_OBJECT_1 => f(Ok(crate::Acquired { client: client.inner.clone(), data: Acquired, diff --git a/tests/helper.rs b/tests/helper.rs index 0b3ba88..f2e1636 100644 --- a/tests/helper.rs +++ b/tests/helper.rs @@ -1,6 +1,5 @@ use jobserver::Client; use std::sync::atomic::*; -use std::sync::mpsc; use std::sync::*; macro_rules! t {