Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Auto merge of #225 - dlrobertson:fmt, r=jdm
rustfmt: Start formatting code

 - Establish a basic rustfmt.toml and add ignore configuration for
   unformatted code.
 - Run `rustfmt` on the following
   - benches/bench.rs
   - src/lib.rs
   - src/router.rs
   - src/test.rs
  • Loading branch information
bors-servo committed Feb 10, 2019
2 parents ef6b155 + 642d148 commit 8779093
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 80 deletions.
12 changes: 8 additions & 4 deletions benches/bench.rs
Expand Up @@ -197,8 +197,10 @@ mod ipc {

fn bench_transfer_senders(b: &mut test::Bencher, count: usize) {
let (main_tx, main_rx) = ipc::channel().unwrap();
let transfer_txs: Vec<_> = (0..count).map(|_| ipc::channel::<()>().unwrap())
.map(|(tx, _)| tx).collect();
let transfer_txs: Vec<_> = (0..count)
.map(|_| ipc::channel::<()>().unwrap())
.map(|(tx, _)| tx)
.collect();
let mut transfer_txs = Some(transfer_txs);
b.iter(|| {
for _ in 0..ITERATIONS {
Expand Down Expand Up @@ -230,8 +232,10 @@ mod ipc {

fn bench_transfer_receivers(b: &mut test::Bencher, count: usize) {
let (main_tx, main_rx) = ipc::channel().unwrap();
let transfer_rxs: Vec<_> = (0..count).map(|_| ipc::channel::<()>().unwrap())
.map(|(_, rx)| rx).collect();
let transfer_rxs: Vec<_> = (0..count)
.map(|_| ipc::channel::<()>().unwrap())
.map(|(_, rx)| rx)
.collect();
let mut transfer_rxs = Some(transfer_rxs);
b.iter(|| {
for _ in 0..ITERATIONS {
Expand Down
9 changes: 9 additions & 0 deletions rustfmt.toml
@@ -0,0 +1,9 @@
match_block_trailing_comma = true
match_arm_blocks = false
binop_separator = "Back"
reorder_imports = true
# TODO(dlrobertson): gradually start formatting files
ignore = [
"src/platform",
"src/ipc.rs"
]
35 changes: 22 additions & 13 deletions src/lib.rs
Expand Up @@ -41,29 +41,38 @@ extern crate crossbeam_channel;

#[macro_use]
extern crate lazy_static;
#[cfg(all(
not(feature = "force-inprocess"),
any(target_os = "linux", target_os = "openbsd", target_os = "freebsd")
))]
extern crate fnv;
extern crate libc;
#[cfg(all(
not(feature = "force-inprocess"),
any(target_os = "linux", target_os = "openbsd", target_os = "freebsd")
))]
extern crate mio;
extern crate rand;
extern crate serde;
#[cfg(any(feature = "force-inprocess", target_os = "windows", target_os = "android", target_os = "ios"))]
extern crate uuid;
extern crate tempfile;
#[cfg(all(not(feature = "force-inprocess"), any(target_os = "linux",
target_os = "openbsd",
target_os = "freebsd")))]
extern crate mio;
#[cfg(all(not(feature = "force-inprocess"), any(target_os = "linux",
target_os = "openbsd",
target_os = "freebsd")))]
extern crate fnv;
#[cfg(all(feature = "memfd", not(feature = "force-inprocess"),
target_os="linux"))]
#[cfg(any(
feature = "force-inprocess",
target_os = "windows",
target_os = "android",
target_os = "ios"
))]
extern crate uuid;
#[cfg(all(
feature = "memfd",
not(feature = "force-inprocess"),
target_os = "linux"
))]
#[macro_use]
extern crate sc;

#[cfg(feature = "async")]
extern crate futures;


pub mod ipc;
pub mod platform;
pub mod router;
Expand Down
31 changes: 14 additions & 17 deletions src/router.rs
Expand Up @@ -12,8 +12,8 @@ use std::sync::Mutex;
use std::thread;

use crossbeam_channel::{self, Receiver, Sender};
use ipc::OpaqueIpcReceiver;
use ipc::{self, IpcReceiver, IpcReceiverSet, IpcSelectionResult, IpcSender, OpaqueIpcMessage};
use ipc::{OpaqueIpcReceiver};
use serde::{Deserialize, Serialize};

lazy_static! {
Expand All @@ -39,7 +39,9 @@ impl RouterProxy {

pub fn add_route(&self, receiver: OpaqueIpcReceiver, callback: RouterHandler) {
let comm = self.comm.lock().unwrap();
comm.msg_sender.send(RouterMsg::AddRoute(receiver, callback)).unwrap();
comm.msg_sender
.send(RouterMsg::AddRoute(receiver, callback))
.unwrap();
comm.wakeup_sender.send(()).unwrap();
}

Expand All @@ -53,9 +55,7 @@ impl RouterProxy {
{
self.add_route(
ipc_receiver.to_opaque(),
Box::new(move |message| {
drop(crossbeam_sender.send(message.to::<T>().unwrap()))
}),
Box::new(move |message| drop(crossbeam_sender.send(message.to::<T>().unwrap()))),
)
}

Expand Down Expand Up @@ -83,7 +83,7 @@ struct Router {
msg_receiver: Receiver<RouterMsg>,
msg_wakeup_id: u64,
ipc_receiver_set: IpcReceiverSet,
handlers: HashMap<u64,RouterHandler>,
handlers: HashMap<u64, RouterHandler>,
}

impl Router {
Expand All @@ -106,22 +106,19 @@ impl Router {
};
for result in results.into_iter() {
match result {
IpcSelectionResult::MessageReceived(id, _) if id == self.msg_wakeup_id => {
IpcSelectionResult::MessageReceived(id, _) if id == self.msg_wakeup_id =>
match self.msg_receiver.recv().unwrap() {
RouterMsg::AddRoute(receiver, handler) => {
let new_receiver_id = self.ipc_receiver_set
.add_opaque(receiver)
.unwrap();
let new_receiver_id =
self.ipc_receiver_set.add_opaque(receiver).unwrap();
self.handlers.insert(new_receiver_id, handler);
}
}
}
IpcSelectionResult::MessageReceived(id, message) => {
self.handlers.get_mut(&id).unwrap()(message)
}
},
},
IpcSelectionResult::MessageReceived(id, message) =>
self.handlers.get_mut(&id).unwrap()(message),
IpcSelectionResult::ChannelClosed(id) => {
self.handlers.remove(&id).unwrap();
}
},
}
}
}
Expand Down

0 comments on commit 8779093

Please sign in to comment.