linux: fix potentially busy loop
I introduced this issue with the recent rate limiting changes. If we generated sufficient events to fill the pipe buffer and trigger an EAGAIN on the write side of the pipe, we'd end up in a state where epoll would continually wake us up to deal with it, but because we gated reading from the pipe on having entries in the queue we could decide that there was nothing to do and leave the pipe unread. This commit adjusts things so that we always try to read some data from it. This is OK because we're using the pipe to knock the main thread out of a sleep rather than as the definitive count of events.
This commit is contained in:
1 parent
185e72b1fe
commit
4e1cfe01a8
2 files changed
+15
-13
No files matched your search
@@ -282,15 +282,9 @@ impl ConnectionOps for Connection {
|
||||
|
||||
match poll.poll(&mut events, Some(period)) {
|
||||
Ok(_) => {
|
||||
for event in &events {
|
||||
let t = event.token();
|
||||
if t == tok_xcb {
|
||||
self.process_queued_xcb()?;
|
||||
} else if t == tok_spawn {
|
||||
SPAWN_QUEUE.run();
|
||||
} else {
|
||||
}
|
||||
}
|
||||
// We process both event sources unconditionally
|
||||
// in the loop above anyway; we're just using
|
||||
// this to get woken up.
|
||||
}
|
||||
|
||||
Err(err) => {
|
||||
|
||||
+12
-4
@@ -141,13 +141,21 @@ impl SpawnQueue {
|
||||
// On linux we only ever process one at at time, so that
|
||||
// we can return to the main loop and process messages
|
||||
// from the X server
|
||||
use std::io::Read;
|
||||
if let Some(func) = self.pop_func() {
|
||||
func();
|
||||
|
||||
let mut byte = [0u8];
|
||||
self.read.lock().unwrap().read(&mut byte).ok();
|
||||
}
|
||||
|
||||
// try to drain the pipe.
|
||||
// We do this regardless of whether we popped an item
|
||||
// so that we avoid being in a perpetually signalled state.
|
||||
// It is ok if we completely drain the pipe because the
|
||||
// main loop uses the return value to set the sleep
|
||||
// interval and will unconditionally call us on each
|
||||
// iteration.
|
||||
let mut byte = [0u8; 64];
|
||||
use std::io::Read;
|
||||
self.read.lock().unwrap().read(&mut byte).ok();
|
||||
|
||||
self.has_any_queued()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user