mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
Merge pull request #174 from asomers/aioprep
Replace magic numbers with constants from mio
This commit is contained in:
+13
-4
@@ -137,6 +137,13 @@ enum Message {
|
|||||||
Run(Box<FnBox>),
|
Run(Box<FnBox>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(usize)]
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
enum Readiness {
|
||||||
|
Readable = 1,
|
||||||
|
Writable = 2,
|
||||||
|
}
|
||||||
|
|
||||||
const TOKEN_MESSAGES: mio::Token = mio::Token(0);
|
const TOKEN_MESSAGES: mio::Token = mio::Token(0);
|
||||||
const TOKEN_FUTURE: mio::Token = mio::Token(1);
|
const TOKEN_FUTURE: mio::Token = mio::Token(1);
|
||||||
const TOKEN_START: usize = 2;
|
const TOKEN_START: usize = 2;
|
||||||
@@ -321,11 +328,13 @@ impl Core {
|
|||||||
if let Some(io) = inner.io_dispatch.get_mut(token) {
|
if let Some(io) = inner.io_dispatch.get_mut(token) {
|
||||||
if ready.is_readable() || ready.is_hup() {
|
if ready.is_readable() || ready.is_hup() {
|
||||||
reader = io.reader.take();
|
reader = io.reader.take();
|
||||||
io.readiness.fetch_or(1, Ordering::Relaxed);
|
io.readiness.fetch_or(Readiness::Readable as usize,
|
||||||
|
Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
if ready.is_writable() {
|
if ready.is_writable() {
|
||||||
writer = io.writer.take();
|
writer = io.writer.take();
|
||||||
io.readiness.fetch_or(2, Ordering::Relaxed);
|
io.readiness.fetch_or(Readiness::Writable as usize,
|
||||||
|
Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drop(inner);
|
drop(inner);
|
||||||
@@ -480,8 +489,8 @@ impl Inner {
|
|||||||
debug!("scheduling direction for: {}", token);
|
debug!("scheduling direction for: {}", token);
|
||||||
let sched = self.io_dispatch.get_mut(token).unwrap();
|
let sched = self.io_dispatch.get_mut(token).unwrap();
|
||||||
let (slot, bit) = match dir {
|
let (slot, bit) = match dir {
|
||||||
Direction::Read => (&mut sched.reader, 1),
|
Direction::Read => (&mut sched.reader, Readiness::Readable as usize),
|
||||||
Direction::Write => (&mut sched.writer, 2),
|
Direction::Write => (&mut sched.writer, Readiness::Writable as usize),
|
||||||
};
|
};
|
||||||
if sched.readiness.load(Ordering::SeqCst) & bit != 0 {
|
if sched.readiness.load(Ordering::SeqCst) & bit != 0 {
|
||||||
*slot = None;
|
*slot = None;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use mio;
|
|||||||
|
|
||||||
use io::Io;
|
use io::Io;
|
||||||
use reactor::{Handle, Remote};
|
use reactor::{Handle, Remote};
|
||||||
|
use reactor::Readiness::*;
|
||||||
use reactor::io_token::IoToken;
|
use reactor::io_token::IoToken;
|
||||||
|
|
||||||
/// A concrete implementation of a stream of readiness notifications for I/O
|
/// A concrete implementation of a stream of readiness notifications for I/O
|
||||||
@@ -98,11 +99,11 @@ impl<E> PollEvented<E> {
|
|||||||
/// to call from within the context of a future's task, typically done in a
|
/// to call from within the context of a future's task, typically done in a
|
||||||
/// `Future::poll` method.
|
/// `Future::poll` method.
|
||||||
pub fn poll_read(&self) -> Async<()> {
|
pub fn poll_read(&self) -> Async<()> {
|
||||||
if self.readiness.load(Ordering::SeqCst) & 1 != 0 {
|
if self.readiness.load(Ordering::SeqCst) & Readable as usize != 0 {
|
||||||
return Async::Ready(())
|
return Async::Ready(())
|
||||||
}
|
}
|
||||||
self.readiness.fetch_or(self.token.take_readiness(), Ordering::SeqCst);
|
self.readiness.fetch_or(self.token.take_readiness(), Ordering::SeqCst);
|
||||||
if self.readiness.load(Ordering::SeqCst) & 1 != 0 {
|
if self.readiness.load(Ordering::SeqCst) & Readable as usize != 0 {
|
||||||
Async::Ready(())
|
Async::Ready(())
|
||||||
} else {
|
} else {
|
||||||
self.token.schedule_read(&self.handle);
|
self.token.schedule_read(&self.handle);
|
||||||
@@ -118,11 +119,11 @@ impl<E> PollEvented<E> {
|
|||||||
/// to call from within the context of a future's task, typically done in a
|
/// to call from within the context of a future's task, typically done in a
|
||||||
/// `Future::poll` method.
|
/// `Future::poll` method.
|
||||||
pub fn poll_write(&self) -> Async<()> {
|
pub fn poll_write(&self) -> Async<()> {
|
||||||
if self.readiness.load(Ordering::SeqCst) & 2 != 0 {
|
if self.readiness.load(Ordering::SeqCst) & Writable as usize != 0 {
|
||||||
return Async::Ready(())
|
return Async::Ready(())
|
||||||
}
|
}
|
||||||
self.readiness.fetch_or(self.token.take_readiness(), Ordering::SeqCst);
|
self.readiness.fetch_or(self.token.take_readiness(), Ordering::SeqCst);
|
||||||
if self.readiness.load(Ordering::SeqCst) & 2 != 0 {
|
if self.readiness.load(Ordering::SeqCst) & Writable as usize != 0 {
|
||||||
Async::Ready(())
|
Async::Ready(())
|
||||||
} else {
|
} else {
|
||||||
self.token.schedule_write(&self.handle);
|
self.token.schedule_write(&self.handle);
|
||||||
@@ -146,7 +147,7 @@ impl<E> PollEvented<E> {
|
|||||||
/// previously indicated that the object is readable. That is, this function
|
/// previously indicated that the object is readable. That is, this function
|
||||||
/// must always be paired with calls to `poll_read` previously.
|
/// must always be paired with calls to `poll_read` previously.
|
||||||
pub fn need_read(&self) {
|
pub fn need_read(&self) {
|
||||||
self.readiness.fetch_and(!1, Ordering::SeqCst);
|
self.readiness.fetch_and(!(Readable as usize), Ordering::SeqCst);
|
||||||
self.token.schedule_read(&self.handle)
|
self.token.schedule_read(&self.handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +167,7 @@ impl<E> PollEvented<E> {
|
|||||||
/// previously indicated that the object is writable. That is, this function
|
/// previously indicated that the object is writable. That is, this function
|
||||||
/// must always be paired with calls to `poll_write` previously.
|
/// must always be paired with calls to `poll_write` previously.
|
||||||
pub fn need_write(&self) {
|
pub fn need_write(&self) {
|
||||||
self.readiness.fetch_and(!2, Ordering::SeqCst);
|
self.readiness.fetch_and(!(Writable as usize), Ordering::SeqCst);
|
||||||
self.token.schedule_write(&self.handle)
|
self.token.schedule_write(&self.handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user