Skip to content

Commit

Permalink
Merge pull request #10 from Sawchord/master
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
dpc committed Mar 11, 2019
2 parents fbbee92 + a85139d commit 20f74e5
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 82 deletions.
15 changes: 8 additions & 7 deletions Cargo.toml
Expand Up @@ -9,20 +9,21 @@ documentation = "https://dpc.github.io/mioco/"
homepage = "https://github.com/dpc/mioco"
repository = "https://github.com/dpc/mioco"
readme = "README.md"
edition = "2018"

[dependencies]
mio = "0.6.6"
mio = "0.6"
lazy_static = "*"
num_cpus = "1.0.0"
context = "1"
num_cpus = "*"
context = "2"
#slog = { version = "2", features = ["max_level_trace", "release_max_level_trace"] }
slog = "2"
slog-term = "~2.0.0-4"
slog-async = "2"
slab = "*"

[dev-dependencies]
env_logger = "0.3.2"
httparse = "1.1.1"
net2 = "0.2.26"
rand = "0.3.14"
env_logger = "0.6"
httparse = "1"
net2 = "0.2"
rand = "0.6"
77 changes: 30 additions & 47 deletions benches/latency.rs
Expand Up @@ -13,25 +13,11 @@ struct SendBencher(*mut Bencher);
// Don't judge me. -- dpc
unsafe impl Send for SendBencher {}

macro_rules! printerrln {
($($arg:tt)*) => ({
use std::io::prelude::*;
if let Err(e) = writeln!(&mut ::std::io::stderr(), "{}",
format_args!($($arg)*)) {
panic!(concat!(
"Failed to write to stderr.\n",
"Original error output: {}\n",
"Secondary error writing to stderr: {}"),
format_args!($($arg)*), e);
}
})
}

//
// WARNING!
//
// Some pieces here are very fragile and will short-circuit on
// any spurious wakeup, eg. when previous task leaves wakup
// any spurious wakeup, eg. when previous task leaves wakeup
// call that was not received by `wait`.
//

Expand All @@ -56,10 +42,9 @@ fn mpsc_pingpong(b: &mut Bencher) {
let join2 = mioco::spawn(move || {
let b = unsafe { &mut *b.0 };
b.iter(|| {

let x = rx2.recv().unwrap();
tx1.send(x + 1).unwrap();
});
let x = rx2.recv().unwrap();
tx1.send(x + 1).unwrap();
});
});

join1.join().unwrap();
Expand All @@ -75,29 +60,28 @@ fn notify_pingpong(b: &mut Bencher) {

let finished = Arc::new(AtomicBool::new(false));
let join1 = mioco::spawn({
let finished = finished.clone();
move || {
while !finished.load(Ordering::SeqCst) {
rx1.reset();
tx2.notify();
rx1.wait();
}
}
});
let finished = finished.clone();
move || {
while !finished.load(Ordering::SeqCst) {
rx1.reset();
tx2.notify();
rx1.wait();
}
}
});

let join2 = mioco::spawn(move || {
let b = unsafe { &mut *b.0 };
b.iter(|| {
rx2.wait();
rx2.reset();
tx1.notify();
});
rx2.wait();
rx2.reset();
tx1.notify();
});
rx2.wait();
finished.store(true, Ordering::SeqCst);
tx1.notify();
});


join1.join().unwrap();
join2.join().unwrap();
}
Expand All @@ -112,29 +96,28 @@ fn broadcast_pingpong(b: &mut Bencher) {
let finished = Arc::new(AtomicBool::new(false));

let join1 = mioco::spawn({
let finished = finished.clone();
move || {
while !finished.load(Ordering::SeqCst) {
rx1.reset();
tx2.notify();
rx1.wait();
}
}
});
let finished = finished.clone();
move || {
while !finished.load(Ordering::SeqCst) {
rx1.reset();
tx2.notify();
rx1.wait();
}
}
});

let join2 = mioco::spawn(move || {
let b = unsafe { &mut *b.0 };
b.iter(|| {
rx2.wait();
rx2.reset();
tx1.notify();
});
rx2.wait();
rx2.reset();
tx1.notify();
});
rx2.wait();
finished.store(true, Ordering::SeqCst);
tx1.notify();
});


join1.join().unwrap();
join2.join().unwrap();
}
2 changes: 1 addition & 1 deletion examples/cheating-http-server.rs
Expand Up @@ -19,7 +19,7 @@ Hello World\r
\r";

fn main() {
env_logger::init().unwrap();
env_logger::init();
let addr = listend_addr();

let listener = TcpListener::bind(&addr).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions examples/echoplus.rs
Expand Up @@ -29,19 +29,19 @@ fn main() {
let _join = mioco::spawn(|| -> io::Result<()> {
let addr = listend_addr();

let listener = try!(TcpListener::bind(&addr));
let listener = TcpListener::bind(&addr)?;

printerrln!("Starting tcp echo server on {:?}", try!(listener.local_addr()));
printerrln!("Starting tcp echo server on {:?}", listener.local_addr()?);

loop {
let (mut conn, _addr) = try!(listener.accept());
let (mut conn, _addr) = listener.accept()?;

let _join = mioco::spawn(move || -> io::Result<()> {
let mut buf = vec![0u8; 1024 * 64];
loop {
let size = try!(conn.read(&mut buf));
let size = conn.read(&mut buf)?;
if size == 0 {/* eof */ break; }
let _ = try!(conn.write_all(&mut buf[0..size]));
let _ = conn.write_all(&mut buf[0..size])?;
}

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions examples/http-server.rs
Expand Up @@ -25,7 +25,7 @@ Hello World";


fn main() {
env_logger::init().unwrap();
env_logger::init();
let addr = listend_addr();

let listener = TcpListener::bind(&addr).unwrap();
Expand All @@ -46,7 +46,7 @@ fn main() {

loop {
let mut headers = [httparse::EMPTY_HEADER; 16];
let len = try!(conn.read(&mut buf[buf_i..]));
let len = conn.read(&mut buf[buf_i..])?;

if len == 0 {
return Ok(());
Expand All @@ -61,14 +61,14 @@ fn main() {
let req_len = res.unwrap();
match req.path {
Some(ref _path) => {
let _ = try!(conn.write_all(&RESPONSE.as_bytes()));
let _ = conn.write_all(&RESPONSE.as_bytes())?;
if req_len != buf_i {
// request has a body; TODO: handle it
}
buf_i = 0;
}
None => {
let _ = try!(conn.write_all(&RESPONSE_404.as_bytes()));
let _ = conn.write_all(&RESPONSE_404.as_bytes())?;
return Ok(());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/fs/file.rs
@@ -1,5 +1,5 @@
use std::io as sio;
use {in_coroutine, offload};
use crate::{in_coroutine, offload};
use std;
use std::path::Path;

Expand Down
30 changes: 18 additions & 12 deletions src/lib.rs
@@ -1,13 +1,7 @@
extern crate mio;
#[macro_use]
extern crate lazy_static;
extern crate context;
#[macro_use]
extern crate slog;
extern crate slog_term;
extern crate slog_async;
extern crate slab;
extern crate num_cpus;

use slog::{Logger, Drain};

Expand Down Expand Up @@ -171,7 +165,9 @@ fn pop_transfer() -> context::Transfer {
}

fn co_switch_out() {
let t = pop_transfer().context.resume(0);
let t = unsafe {
pop_transfer().context.resume(0)
};
save_transfer(t);
}

Expand All @@ -194,15 +190,19 @@ extern "C" fn context_function(t: context::Transfer) -> ! {
cell.borrow_mut().take().unwrap()
};

let t = t.context.resume(0);
let t = unsafe {
t.context.resume(0)
};

save_transfer(t);

let _res = f.invoke(());
}

loop {
save_transfer(pop_transfer().context.resume(1));
save_transfer(unsafe{
pop_transfer().context.resume(1)
});
}
}

Expand Down Expand Up @@ -233,8 +233,12 @@ impl Fiber {

let stack = stack::ProtectedFixedSizeStack::default();

let context = context::Context::new(&stack, context_function);
let t = context.resume(&f as *const _ as usize);
let context = unsafe {
context::Context::new(&stack, context_function)
};
let t = unsafe {
context.resume(&f as *const _ as usize)
};
debug_assert!(f.borrow().is_none());

trace!(log, "fiber created");
Expand All @@ -248,7 +252,9 @@ impl Fiber {
fn resume(&mut self, loop_id: LoopId, fiber_id: FiberId) {
TL_LOOP_ID.with(|id| id.set(loop_id));
TL_FIBER_ID.with(|id| id.set(fiber_id));
let t = self.cur_context.take().unwrap().resume(0);
let t = unsafe {
self.cur_context.take().unwrap().resume(0)
};
self.cur_context = Some(t.context);
TL_LOOP_ID.with(|id| id.set(TL_LOOP_ID_NONE));
TL_FIBER_ID.with(|id| id.set(TL_FIBER_ID_NONE));
Expand Down
2 changes: 1 addition & 1 deletion src/net/tcp.rs
Expand Up @@ -33,7 +33,7 @@ impl TcpListener {
}

/// Creates a new TcpListener from an instance of a `std::net::TcpListener` type.
pub fn from_listener(listener: std::net::TcpListener, addr: &SocketAddr) -> io::Result<Self> {
pub fn from_listener(listener: std::net::TcpListener, _addr: &SocketAddr) -> io::Result<Self> {
mio::tcp::TcpListener::from_std(listener).map(AsyncIO::new)
}

Expand Down
2 changes: 1 addition & 1 deletion src/sync/broadcast.rs
@@ -1,7 +1,7 @@
//! Broadcast allows waking up multiple receivers at once
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicUsize, Ordering};
use {MIOCO, co_switch_out, get_cur_fullid, FullId};
use crate::{MIOCO, co_switch_out, get_cur_fullid, FullId};
use std::collections::HashSet;
use std::mem;
use std::cell::RefCell;
Expand Down
2 changes: 1 addition & 1 deletion src/sync/mpsc.rs
Expand Up @@ -90,7 +90,7 @@ impl<T> Sender<T> {
///
/// This is non-blocking operation.
pub fn send(&self, t: T) -> Result<(), mpsc::SendError<T>> {
try!(self.tx.as_ref().unwrap().send(t));
self.tx.as_ref().unwrap().send(t)?;
self.notif_tx.notify();
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/sync/mutex.rs
@@ -1,5 +1,5 @@
use super::broadcast;
use {in_coroutine};
use crate::in_coroutine;

use std::sync as ssync;
use std::ops;
Expand Down
2 changes: 1 addition & 1 deletion src/sync/notify.rs
@@ -1,6 +1,6 @@
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering};
use {MIOCO, LoopMsg, FiberId, co_switch_out, TL_LOOP_ID, TL_FIBER_ID};
use crate::{MIOCO, LoopMsg, FiberId, co_switch_out, TL_LOOP_ID, TL_FIBER_ID};
use std;

struct Shared {
Expand Down

0 comments on commit 20f74e5

Please sign in to comment.