mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
Merge pull request #253 from alexcrichton/perf
Conditionally call `consume_queue` on messages
This commit is contained in:
commit
fb05eb34af
@ -580,9 +580,22 @@ impl Remote {
|
|||||||
self.with_loop(|lp| {
|
self.with_loop(|lp| {
|
||||||
match lp {
|
match lp {
|
||||||
Some(lp) => {
|
Some(lp) => {
|
||||||
// Need to execute all existing requests first, to ensure
|
// We want to make sure that all messages are received in
|
||||||
// that our message is processed "in order"
|
// order, so we need to consume pending messages before
|
||||||
lp.consume_queue();
|
// delivering this message to the core. The actually
|
||||||
|
// `consume_queue` function, however, can be somewhat slow
|
||||||
|
// right now where receiving on a channel will acquire a
|
||||||
|
// lock and block the current task.
|
||||||
|
//
|
||||||
|
// To speed this up check the message queue's readiness as a
|
||||||
|
// sort of preflight check to see if we've actually got any
|
||||||
|
// messages. This should just involve some atomics and if it
|
||||||
|
// comes back false then we know for sure there are no
|
||||||
|
// pending messages, so we can immediately deliver our
|
||||||
|
// message.
|
||||||
|
if lp.rx_readiness.0.readiness().is_readable() {
|
||||||
|
lp.consume_queue();
|
||||||
|
}
|
||||||
lp.notify(msg);
|
lp.notify(msg);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user