From 3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:43 +0200 Subject: Merging upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/jobserver/src/windows.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'vendor/jobserver/src/windows.rs') diff --git a/vendor/jobserver/src/windows.rs b/vendor/jobserver/src/windows.rs index d795c1cee..6791efea4 100644 --- a/vendor/jobserver/src/windows.rs +++ b/vendor/jobserver/src/windows.rs @@ -170,6 +170,26 @@ impl Client { self.name.clone() } + pub fn available(&self) -> io::Result { + // Can't read value of a semaphore on Windows, so + // try to acquire without sleeping, since we can find out the + // old value on release. If acquisiton fails, then available is 0. + unsafe { + let r = WaitForSingleObject(self.sem.0, 0); + if r != WAIT_OBJECT_0 { + Ok(0) + } else { + let mut prev: LONG = 0; + let r = ReleaseSemaphore(self.sem.0, 1, &mut prev); + if r != 0 { + Ok(prev as usize + 1) + } else { + Err(io::Error::last_os_error()) + } + } + } + } + pub fn configure(&self, _cmd: &mut Command) { // nothing to do here, we gave the name of our semaphore to the // child above -- cgit v1.2.3