Closed NobodyXu closed 4 months ago
On unix, when the named fifo is used and on Windows, it is possible to acquire without blocking.
For named fifo on unix, we can simply set pipe to be non-blocking before reading.
read
https://github.com/rust-lang/cc-rs/blob/2f587f5561fb9c3c02e5c9e186b2bea98691608a/src/parallel/job_token/unix.rs#L113
On windows, we can use WaitForSingleObject(self.sem, 0):
WaitForSingleObject(self.sem, 0)
https://github.com/rust-lang/cc-rs/blob/2f587f5561fb9c3c02e5c9e186b2bea98691608a/src/parallel/job_token/windows.rs#L44
On Linux, we can also applies an optimization, to turn an annoymous pipe into a named fifo:
https://github.com/rust-lang/cc-rs/blob/2f587f5561fb9c3c02e5c9e186b2bea98691608a/src/parallel/job_token/unix.rs#L77
Though that optimization is verified to be incorrect on macOS, opening /dev/fd/$fd seems to return the same file description.
/dev/fd/$fd
My proposal is add two new APIs to Client:
Client
impl Client { fn try_acquire(&self) -> io::Result<Option<Acquired>>; fn supports_try_acquire(&self) -> bool; }
On unix, when the named fifo is used and on Windows, it is possible to acquire without blocking.
For named fifo on unix, we can simply set pipe to be non-blocking before
read
ing.https://github.com/rust-lang/cc-rs/blob/2f587f5561fb9c3c02e5c9e186b2bea98691608a/src/parallel/job_token/unix.rs#L113
On windows, we can use
WaitForSingleObject(self.sem, 0)
:https://github.com/rust-lang/cc-rs/blob/2f587f5561fb9c3c02e5c9e186b2bea98691608a/src/parallel/job_token/windows.rs#L44
On Linux, we can also applies an optimization, to turn an annoymous pipe into a named fifo:
https://github.com/rust-lang/cc-rs/blob/2f587f5561fb9c3c02e5c9e186b2bea98691608a/src/parallel/job_token/unix.rs#L77
Though that optimization is verified to be incorrect on macOS, opening
/dev/fd/$fd
seems to return the same file description.