aboutsummaryrefslogtreecommitdiffstats
path: root/components/util
diff options
context:
space:
mode:
authorDirkjan Ochtman <dirkjan@ochtman.nl>2016-10-19 10:05:11 +0200
committerMs2ger <Ms2ger@gmail.com>2016-10-19 10:05:33 +0200
commita1c69119723c5fe49b3f7539207716e1f48ddcfa (patch)
tree79819baf400f31e1a22031f62523ef75d2a755cf /components/util
parentf4ed2c6875e4f766b4de93263a25431424215f73 (diff)
downloadservo-a1c69119723c5fe49b3f7539207716e1f48ddcfa.tar.gz
servo-a1c69119723c5fe49b3f7539207716e1f48ddcfa.zip
Remove util::ipc module (fixes #12312)
Diffstat (limited to 'components/util')
-rw-r--r--components/util/Cargo.toml3
-rw-r--r--components/util/ipc.rs179
-rw-r--r--components/util/lib.rs2
3 files changed, 1 insertions, 183 deletions
diff --git a/components/util/Cargo.toml b/components/util/Cargo.toml
index c024f21e92d..668470200b7 100644
--- a/components/util/Cargo.toml
+++ b/components/util/Cargo.toml
@@ -11,7 +11,7 @@ path = "lib.rs"
[features]
# servo as opposed to geckolib
-servo = ["serde", "serde_derive", "ipc-channel", "app_units/plugins",
+servo = ["serde", "serde_derive", "app_units/plugins",
"euclid/unstable", "url/heap_size", "url/serde", "plugins"]
[dependencies]
@@ -20,7 +20,6 @@ bitflags = "0.7"
euclid = "0.10.1"
getopts = "0.2.11"
heapsize = "0.3.0"
-ipc-channel = {version = "0.5", optional = true}
lazy_static = "0.2"
log = "0.3.5"
num_cpus = "0.2.2"
diff --git a/components/util/ipc.rs b/components/util/ipc.rs
deleted file mode 100644
index e6f81d55940..00000000000
--- a/components/util/ipc.rs
+++ /dev/null
@@ -1,179 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-use ipc_channel::ipc::{self, IpcSender, OpaqueIpcSender};
-use ipc_channel::router::ROUTER;
-use opts;
-use serde::{Deserialize, Deserializer, Serialize, Serializer};
-use std::any::{Any, TypeId};
-use std::collections::HashMap;
-use std::io::{Error, ErrorKind};
-use std::marker::Reflect;
-use std::mem;
-use std::sync::Mutex;
-use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
-use std::sync::mpsc::{self, Receiver, Sender};
-
-lazy_static! {
- static ref IN_PROCESS_SENDERS: Mutex<HashMap<usize, OpaqueSender>> =
- Mutex::new(HashMap::new());
-}
-
-static NEXT_SENDER_ID: AtomicUsize = ATOMIC_USIZE_INIT;
-
-pub enum OptionalIpcSender<T> where T: Deserialize + Serialize + Send + Any {
- OutOfProcess(IpcSender<T>),
- InProcess(Sender<T>),
-}
-
-impl<T> OptionalIpcSender<T> where T: Deserialize + Serialize + Send + Any {
- pub fn send(&self, value: T) -> Result<(), Error> {
- match *self {
- OptionalIpcSender::OutOfProcess(ref ipc_sender) => ipc_sender.send(value),
- OptionalIpcSender::InProcess(ref sender) => {
- sender.send(value).map_err(|_| Error::new(ErrorKind::Other, "MPSC send failed"))
- }
- }
- }
-
- pub fn to_opaque(self) -> OptionalOpaqueIpcSender {
- match self {
- OptionalIpcSender::OutOfProcess(ipc_sender) => {
- OptionalOpaqueIpcSender::OutOfProcess(ipc_sender.to_opaque())
- }
- OptionalIpcSender::InProcess(sender) => {
- OptionalOpaqueIpcSender::InProcess(OpaqueSender::new(sender))
- }
- }
- }
-}
-
-impl<T> Clone for OptionalIpcSender<T> where T: Deserialize + Serialize + Send + Any {
- fn clone(&self) -> OptionalIpcSender<T> {
- match *self {
- OptionalIpcSender::OutOfProcess(ref ipc_sender) => {
- OptionalIpcSender::OutOfProcess((*ipc_sender).clone())
- }
- OptionalIpcSender::InProcess(ref sender) => {
- OptionalIpcSender::InProcess((*sender).clone())
- }
- }
- }
-}
-
-impl<T> Deserialize for OptionalIpcSender<T> where T: Deserialize + Serialize + Send + Any {
- fn deserialize<D>(deserializer: &mut D)
- -> Result<OptionalIpcSender<T>, D::Error> where D: Deserializer {
- if opts::multiprocess() {
- return Ok(OptionalIpcSender::OutOfProcess(try!(Deserialize::deserialize(
- deserializer))))
- }
- let id: usize = try!(Deserialize::deserialize(deserializer));
- let sender = IN_PROCESS_SENDERS.lock().unwrap().remove(&id).unwrap();
- Ok(OptionalIpcSender::InProcess(sender.to().unwrap()))
- }
-}
-
-impl<T> Serialize for OptionalIpcSender<T> where T: Deserialize + Serialize + Send + Any {
- fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
- match *self {
- OptionalIpcSender::OutOfProcess(ref ipc_sender) => ipc_sender.serialize(serializer),
- OptionalIpcSender::InProcess(ref sender) => {
- let id = NEXT_SENDER_ID.fetch_add(1, Ordering::SeqCst);
- IN_PROCESS_SENDERS.lock()
- .unwrap()
- .insert(id, OpaqueSender::new((*sender).clone()));
- id.serialize(serializer)
- }
- }
- }
-}
-
-#[derive(Clone)]
-pub enum OptionalOpaqueIpcSender {
- OutOfProcess(OpaqueIpcSender),
- InProcess(OpaqueSender),
-}
-
-impl OptionalOpaqueIpcSender {
- pub fn to<T>(self) -> OptionalIpcSender<T>
- where T: Deserialize + Serialize + Send + Any + 'static {
- match self {
- OptionalOpaqueIpcSender::OutOfProcess(ipc_sender) => {
- OptionalIpcSender::OutOfProcess(ipc_sender.to())
- }
- OptionalOpaqueIpcSender::InProcess(sender) => {
- OptionalIpcSender::InProcess(sender.to().unwrap())
- }
- }
- }
-}
-
-impl Deserialize for OptionalOpaqueIpcSender {
- fn deserialize<D>(deserializer: &mut D)
- -> Result<OptionalOpaqueIpcSender, D::Error> where D: Deserializer {
- if opts::multiprocess() {
- return Ok(OptionalOpaqueIpcSender::OutOfProcess(try!(Deserialize::deserialize(
- deserializer))))
- }
- let id: usize = try!(Deserialize::deserialize(deserializer));
- let sender = IN_PROCESS_SENDERS.lock().unwrap().remove(&id).unwrap();
- Ok(OptionalOpaqueIpcSender::InProcess(sender))
- }
-}
-
-impl Serialize for OptionalOpaqueIpcSender {
- fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
- match *self {
- OptionalOpaqueIpcSender::OutOfProcess(ref ipc_sender) => {
- ipc_sender.serialize(serializer)
- }
- OptionalOpaqueIpcSender::InProcess(ref sender) => {
- let id = NEXT_SENDER_ID.fetch_add(1, Ordering::SeqCst);
- IN_PROCESS_SENDERS.lock().unwrap().insert(id, (*sender).clone());
- id.serialize(serializer)
- }
- }
- }
-}
-
-#[derive(Clone)]
-pub struct OpaqueSender {
- sender: Sender<()>,
- id: TypeId,
-}
-
-impl OpaqueSender {
- fn new<T>(sender: Sender<T>) -> OpaqueSender where T: 'static + Reflect + Send {
- unsafe {
- OpaqueSender {
- sender: mem::transmute::<_, Sender<()>>(sender),
- id: TypeId::of::<T>(),
- }
- }
- }
-
- fn to<T>(self) -> Option<Sender<T>> where T: 'static + Reflect + Send {
- unsafe {
- if self.id != TypeId::of::<T>() {
- None
- } else {
- Some(mem::transmute::<_, Sender<T>>(self.sender))
- }
- }
- }
-}
-
-pub fn optional_ipc_channel<T>() -> (OptionalIpcSender<T>, Receiver<T>)
- where T: Deserialize + Serialize + Send + Any {
- if opts::multiprocess() {
- let (ipc_sender, ipc_receiver) = ipc::channel().unwrap();
- let receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_receiver);
- (OptionalIpcSender::OutOfProcess(ipc_sender), receiver)
- } else {
- let (sender, receiver) = mpsc::channel();
- (OptionalIpcSender::InProcess(sender), receiver)
- }
-}
-
diff --git a/components/util/lib.rs b/components/util/lib.rs
index ee3bb09921e..931cd2dc1a5 100644
--- a/components/util/lib.rs
+++ b/components/util/lib.rs
@@ -18,7 +18,6 @@ extern crate core;
#[macro_use] extern crate euclid;
extern crate getopts;
#[macro_use] extern crate heapsize;
-#[cfg(feature = "servo")] extern crate ipc_channel;
#[allow(unused_extern_crates)] #[macro_use] extern crate lazy_static;
#[macro_use] extern crate log;
extern crate num_cpus;
@@ -31,7 +30,6 @@ extern crate xdg;
pub mod basedir;
pub mod geometry;
-#[cfg(feature = "servo")] #[allow(unsafe_code)] pub mod ipc;
#[allow(unsafe_code)] pub mod opts;
pub mod prefs;
#[cfg(feature = "servo")] pub mod remutex;