Skip to content

Commit

Permalink
Fix warnings from rustc and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Apr 11, 2024
1 parent 507eb38 commit 3dea952
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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=<VALUE>` in the given
Expand Down
17 changes: 9 additions & 8 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) => {}
}
});
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()?;
}
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion tests/helper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use jobserver::Client;
use std::sync::atomic::*;
use std::sync::mpsc;
use std::sync::*;

macro_rules! t {
Expand Down

0 comments on commit 3dea952

Please sign in to comment.