Revert to crossbeam
This commit is contained in:
21
Cargo.lock
generated
21
Cargo.lock
generated
@@ -175,6 +175,24 @@ dependencies = [
|
|||||||
"pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-channel"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-mac"
|
name = "crypto-mac"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@@ -1212,6 +1230,7 @@ dependencies = [
|
|||||||
"chacha20poly1305 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"chacha20poly1305 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"cpuprofiler 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cpuprofiler 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"daemonize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"daemonize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -1303,6 +1322,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17"
|
"checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17"
|
||||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||||
"checksum cpuprofiler 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "43f8479dbcfd2bbaa0c0c26779b913052b375981cdf533091f2127ea3d42e52b"
|
"checksum cpuprofiler 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "43f8479dbcfd2bbaa0c0c26779b913052b375981cdf533091f2127ea3d42e52b"
|
||||||
|
"checksum crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "acec9a3b0b3559f15aee4f90746c4e5e293b701c0f7d3925d24e01645267b68c"
|
||||||
|
"checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4"
|
||||||
"checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5"
|
"checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5"
|
||||||
"checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d"
|
"checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d"
|
||||||
"checksum daemonize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "70c24513e34f53b640819f0ac9f705b673fcf4006d7aab8778bee72ebfc89815"
|
"checksum daemonize 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "70c24513e34f53b640819f0ac9f705b673fcf4006d7aab8778bee72ebfc89815"
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ clear_on_drop = "0.2.3"
|
|||||||
env_logger = "0.6"
|
env_logger = "0.6"
|
||||||
num_cpus = "^1.10"
|
num_cpus = "^1.10"
|
||||||
daemonize = "0.4.1"
|
daemonize = "0.4.1"
|
||||||
|
crossbeam-channel = "0.4"
|
||||||
cpuprofiler = { version = "*", optional = true }
|
cpuprofiler = { version = "*", optional = true }
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
|
|||||||
@@ -180,14 +180,11 @@ fn main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::info!("UAPI error: {}", err);
|
log::info!("UAPI connection error: {}", err);
|
||||||
break;
|
profiler_stop();
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// exit
|
|
||||||
profiler_stop();
|
|
||||||
exit(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// block until all tun readers closed
|
// block until all tun readers closed
|
||||||
|
|||||||
@@ -1,19 +1,8 @@
|
|||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||||
use std::sync::mpsc::sync_channel;
|
|
||||||
use std::sync::mpsc::{Receiver, SyncSender};
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
/// A simple parallel queue used to pass work to a worker pool.
|
|
||||||
///
|
|
||||||
/// Unlike e.g. the crossbeam multi-producer multi-consumer queue
|
|
||||||
/// the ParallelQueue offers fewer features and instead improves speed:
|
|
||||||
///
|
|
||||||
/// The crossbeam channel ensures that elements are consumed
|
|
||||||
/// even if not every Receiver is being read from.
|
|
||||||
/// This is not ensured by ParallelQueue.
|
|
||||||
pub struct ParallelQueue<T> {
|
pub struct ParallelQueue<T> {
|
||||||
next: AtomicUsize, // next round-robin index
|
queue: Mutex<Option<Sender<T>>>, // work queues (1 per thread)
|
||||||
queues: Vec<Mutex<Option<SyncSender<T>>>>, // work queues (1 per thread)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ParallelQueue<T> {
|
impl<T> ParallelQueue<T> {
|
||||||
@@ -25,40 +14,26 @@ impl<T> ParallelQueue<T> {
|
|||||||
/// - `capacity`: capacity of each internal queue
|
/// - `capacity`: capacity of each internal queue
|
||||||
///
|
///
|
||||||
pub fn new(queues: usize, capacity: usize) -> (Self, Vec<Receiver<T>>) {
|
pub fn new(queues: usize, capacity: usize) -> (Self, Vec<Receiver<T>>) {
|
||||||
let mut rxs = vec![];
|
let mut receivers = Vec::with_capacity(queues);
|
||||||
let mut txs = vec![];
|
let (tx, rx) = bounded(capacity);
|
||||||
|
|
||||||
for _ in 0..queues {
|
for _ in 0..queues {
|
||||||
let (tx, rx) = sync_channel(capacity);
|
receivers.push(rx.clone());
|
||||||
txs.push(Mutex::new(Some(tx)));
|
|
||||||
rxs.push(rx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
ParallelQueue {
|
ParallelQueue {
|
||||||
next: AtomicUsize::new(0),
|
queue: Mutex::new(Some(tx)),
|
||||||
queues: txs,
|
|
||||||
},
|
},
|
||||||
rxs,
|
receivers,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&self, v: T) {
|
pub fn send(&self, v: T) {
|
||||||
let len = self.queues.len();
|
self.queue.lock().unwrap().as_ref().map(|s| {
|
||||||
let idx = self.next.fetch_add(1, Ordering::SeqCst);
|
let _ = s.send(v);
|
||||||
match self.queues[idx % len].lock().unwrap().as_ref() {
|
});
|
||||||
Some(que) => {
|
|
||||||
// TODO: consider best way to propergate Result
|
|
||||||
let _ = que.send(v);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(&self) {
|
pub fn close(&self) {
|
||||||
for i in 0..self.queues.len() {
|
*self.queue.lock().unwrap() = None;
|
||||||
let queue = &self.queues[i];
|
|
||||||
*queue.lock().unwrap() = None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ use super::runq::RunQueue;
|
|||||||
use super::types::Callbacks;
|
use super::types::Callbacks;
|
||||||
use super::{tun, udp, Endpoint};
|
use super::{tun, udp, Endpoint};
|
||||||
|
|
||||||
|
use crossbeam_channel::Receiver;
|
||||||
use ring::aead::{Aad, LessSafeKey, Nonce, UnboundKey, CHACHA20_POLY1305};
|
use ring::aead::{Aad, LessSafeKey, Nonce, UnboundKey, CHACHA20_POLY1305};
|
||||||
use zerocopy::{AsBytes, LayoutVerified};
|
use zerocopy::{AsBytes, LayoutVerified};
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::mpsc::Receiver;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub const SIZE_TAG: usize = 16;
|
pub const SIZE_TAG: usize = 16;
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ use super::KeyPair;
|
|||||||
use super::REJECT_AFTER_MESSAGES;
|
use super::REJECT_AFTER_MESSAGES;
|
||||||
use super::{tun, udp, Endpoint};
|
use super::{tun, udp, Endpoint};
|
||||||
|
|
||||||
use std::sync::mpsc::Receiver;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crossbeam_channel::Receiver;
|
||||||
use ring::aead::{Aad, LessSafeKey, Nonce, UnboundKey, CHACHA20_POLY1305};
|
use ring::aead::{Aad, LessSafeKey, Nonce, UnboundKey, CHACHA20_POLY1305};
|
||||||
use zerocopy::{AsBytes, LayoutVerified};
|
use zerocopy::{AsBytes, LayoutVerified};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use arraydeque::ArrayDeque;
|
|
||||||
use spin::{Mutex, MutexGuard};
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::sync::mpsc::Receiver;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use arraydeque::ArrayDeque;
|
||||||
|
use crossbeam_channel::Receiver;
|
||||||
|
use spin::{Mutex, MutexGuard};
|
||||||
|
|
||||||
use super::constants::INORDER_QUEUE_SIZE;
|
use super::constants::INORDER_QUEUE_SIZE;
|
||||||
use super::runq::{RunQueue, ToKey};
|
use super::runq::{RunQueue, ToKey};
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
use std::sync::mpsc::Receiver;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use futures::sync::oneshot;
|
|
||||||
use futures::*;
|
|
||||||
|
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
|
|
||||||
use ring::aead::{Aad, LessSafeKey, Nonce, UnboundKey, CHACHA20_POLY1305};
|
use ring::aead::{Aad, LessSafeKey, Nonce, UnboundKey, CHACHA20_POLY1305};
|
||||||
|
|
||||||
|
use crossbeam_channel::Receiver;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use zerocopy::{AsBytes, LayoutVerified};
|
use zerocopy::{AsBytes, LayoutVerified};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user