diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml index bc324c95c33..2cc47ccf87e 100644 --- a/components/net/Cargo.toml +++ b/components/net/Cargo.toml @@ -41,6 +41,7 @@ log = "0.3.5" mime_guess = "1.6.0" openssl = "0.7.6" rustc-serialize = "0.3" +threadpool = "1.0" time = "0.1.17" url = {version = "0.5.7", features = ["heap_size"]} uuid = "0.1.16" diff --git a/components/net/image_cache_thread.rs b/components/net/image_cache_thread.rs index 46c0037d126..91a0cf0dc32 100644 --- a/components/net/image_cache_thread.rs +++ b/components/net/image_cache_thread.rs @@ -19,10 +19,10 @@ use std::io::Read; use std::mem; use std::sync::Arc; use std::sync::mpsc::{Sender, Receiver, channel}; +use threadpool::ThreadPool; use url::Url; use util::resource_files::resources_dir_path; use util::thread::spawn_named; -use util::threadpool::ThreadPool; use webrender_traits; /// diff --git a/components/net/lib.rs b/components/net/lib.rs index ac740a5b9aa..2b008a89a32 100644 --- a/components/net/lib.rs +++ b/components/net/lib.rs @@ -25,6 +25,7 @@ extern crate msg; extern crate net_traits; extern crate openssl; extern crate rustc_serialize; +extern crate threadpool; extern crate time; extern crate url; extern crate util; diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 6cebaa2afed..6a2284d2043 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -1280,6 +1280,7 @@ dependencies = [ "openssl 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "threadpool 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", "util 0.0.1", @@ -2064,6 +2065,11 @@ dependencies = [ "utf-8 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "threadpool" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "time" version = "0.1.34" diff --git a/components/util/lib.rs b/components/util/lib.rs index 93cb5de4cc1..d1f9f65644c 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -7,7 +7,6 @@ #![feature(core_intrinsics)] #![feature(custom_derive)] #![cfg_attr(feature = "non-geckolib", feature(decode_utf16))] -#![feature(fnbox)] #![feature(optin_builtin_traits)] #![feature(plugin)] #![feature(reflect_marker)] @@ -59,7 +58,6 @@ pub mod resource_files; pub mod str; pub mod thread; pub mod thread_state; -pub mod threadpool; pub mod tid; pub mod time; pub mod vec; diff --git a/components/util/threadpool.rs b/components/util/threadpool.rs deleted file mode 100644 index 67bbd08b072..00000000000 --- a/components/util/threadpool.rs +++ /dev/null @@ -1,55 +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/. */ - -//! A load-balancing thread pool. -//! -//! This differs in implementation from std::sync::ThreadPool in that each job is -//! up for grabs by any of the child threads in the pool. -//! - -// -// This is based on the cargo thread pool. -// https://github.com/rust-lang/cargo/blob/master/src/cargo/util/pool.rs -// -// The only difference is that a normal channel is used instead of a sync_channel. -// - -use std::boxed::FnBox; -use std::sync::mpsc::{Receiver, Sender, channel}; -use std::sync::{Arc, Mutex}; -use thread::spawn_named; - -pub struct ThreadPool { - tx: Sender>, -} - -impl ThreadPool { - pub fn new(threads: u32) -> ThreadPool { - assert!(threads > 0); - let (tx, rx) = channel(); - - let state = Arc::new(Mutex::new(rx)); - - for i in 0..threads { - let state = state.clone(); - spawn_named( - format!("ThreadPoolWorker {}/{}", i + 1, threads), - move || worker(&*state)); - } - - return ThreadPool { tx: tx }; - - fn worker(rx: &Mutex>>) { - while let Ok(job) = rx.lock().unwrap().recv() { - job.call_box(()); - } - } - } - - pub fn execute(&self, job: F) - where F: FnOnce() + Send + 'static - { - self.tx.send(Box::new(job)).unwrap(); - } -} diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 1f7178b1334..d3f1f4bec43 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -1200,6 +1200,7 @@ dependencies = [ "openssl 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "threadpool 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", "util 0.0.1", @@ -1951,6 +1952,11 @@ dependencies = [ "utf-8 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "threadpool" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "time" version = "0.1.34" diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index cd4e33663b2..6da00e67649 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -1182,6 +1182,7 @@ dependencies = [ "openssl 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "threadpool 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", "util 0.0.1", @@ -1931,6 +1932,11 @@ dependencies = [ "utf-8 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "threadpool" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "time" version = "0.1.34"