task -> thread

This commit is contained in:
rohan.prinja 2015-11-14 05:07:55 +09:00 committed by Rohan Prinja
parent f00532bab0
commit 1f02c4ebbb
119 changed files with 1209 additions and 1207 deletions

View file

@ -69,9 +69,9 @@ pub mod print_tree;
pub mod range;
pub mod resource_files;
pub mod str;
pub mod task;
pub mod task_state;
pub mod taskpool;
pub mod thread;
pub mod thread_state;
pub mod threadpool;
pub mod tid;
pub mod time;
pub mod vec;

View file

@ -119,7 +119,7 @@ pub struct Opts {
/// and paint.
pub trace_layout: bool,
/// Periodically print out on which events script tasks spend their processing time.
/// Periodically print out on which events script threads spend their processing time.
pub profile_script_events: bool,
/// Enable all heartbeats for profiling.
@ -224,7 +224,7 @@ pub struct DebugOptions {
/// Print notifications when there is a relayout.
pub relayout_event: bool,
/// Profile which events script tasks spend their time on.
/// Profile which events script threads spend their time on.
pub profile_script_events: bool,
/// Enable all heartbeats for profiling.
@ -334,7 +334,7 @@ pub fn print_debug_usage(app: &str) -> ! {
print_option("dump-layer-tree", "Print the layer tree whenever it changes.");
print_option("relayout-event", "Print notifications when there is a relayout.");
print_option("profile-script-events", "Enable profiling of script-related events.");
print_option("profile-heartbeats", "Enable heartbeats for all task categories.");
print_option("profile-heartbeats", "Enable heartbeats for all thread categories.");
print_option("show-compositor-borders", "Paint borders along layer and tile boundaries.");
print_option("show-fragment-borders", "Paint borders along fragment boundaries.");
print_option("show-parallel-paint", "Overlay tiles with colors showing which thread painted them.");
@ -507,7 +507,7 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
opts.optmulti("", "user-stylesheet",
"A user stylesheet to be added to every document", "file.css");
opts.optflag("z", "headless", "Headless mode");
opts.optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure");
opts.optflag("f", "hard-fail", "Exit on thread failure instead of displaying about:failure");
opts.optflagopt("", "devtools", "Start remote devtools server on port", "6000");
opts.optflagopt("", "webdriver", "Start remote WebDriver server on port", "7000");
opts.optopt("", "resolution", "Set window resolution.", "800x600");

View file

@ -8,7 +8,7 @@ use std::borrow::ToOwned;
use std::sync::mpsc::Sender;
use std::thread;
use std::thread::Builder;
use task_state;
use thread_state;
pub fn spawn_named<F>(name: String, f: F)
where F: FnOnce() + Send + 'static
@ -38,9 +38,9 @@ impl<T> SendOnFailure for IpcSender<T> where T: Send + Serialize + 'static {
}
}
/// Arrange to send a particular message to a channel if the task fails.
/// Arrange to send a particular message to a channel if the thread fails.
pub fn spawn_named_with_send_on_failure<F, T, S>(name: String,
state: task_state::TaskState,
state: thread_state::ThreadState,
f: F,
msg: T,
mut dest: S)
@ -48,7 +48,7 @@ pub fn spawn_named_with_send_on_failure<F, T, S>(name: String,
T: Send + 'static,
S: Send + SendOnFailure<Value=T> + 'static {
let future_handle = thread::Builder::new().name(name.to_owned()).spawn(move || {
task_state::initialize(state);
thread_state::initialize(state);
f()
}).unwrap();

View file

@ -2,7 +2,7 @@
* 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/. */
//! Supports dynamic assertions in debug builds about what sort of task is
//! Supports dynamic assertions in debug builds about what sort of thread is
//! running and what state it's in.
//!
//! In release builds, `get` returns 0. All of the other functions inline
@ -11,7 +11,7 @@
pub use self::imp::{enter, exit, get, initialize};
bitflags! {
flags TaskState: u32 {
flags ThreadState: u32 {
const SCRIPT = 0x01,
const LAYOUT = 0x02,
const PAINT = 0x04,
@ -22,8 +22,8 @@ bitflags! {
}
}
macro_rules! task_types ( ( $( $fun:ident = $flag:ident ; )* ) => (
impl TaskState {
macro_rules! thread_types ( ( $( $fun:ident = $flag:ident ; )* ) => (
impl ThreadState {
$(
#[cfg(debug_assertions)]
pub fn $fun(self) -> bool {
@ -37,11 +37,11 @@ macro_rules! task_types ( ( $( $fun:ident = $flag:ident ; )* ) => (
}
#[cfg(debug_assertions)]
static TYPES: &'static [TaskState]
static TYPES: &'static [ThreadState]
= &[ $( $flag ),* ];
));
task_types! {
thread_types! {
is_script = SCRIPT;
is_layout = LAYOUT;
is_paint = PAINT;
@ -50,14 +50,14 @@ task_types! {
#[cfg(debug_assertions)]
mod imp {
use std::cell::RefCell;
use super::{TYPES, TaskState};
use super::{TYPES, ThreadState};
thread_local!(static STATE: RefCell<Option<TaskState>> = RefCell::new(None));
thread_local!(static STATE: RefCell<Option<ThreadState>> = RefCell::new(None));
pub fn initialize(x: TaskState) {
pub fn initialize(x: ThreadState) {
STATE.with(|ref k| {
match *k.borrow() {
Some(s) => panic!("Task state already initialized as {:?}", s),
Some(s) => panic!("Thread state already initialized as {:?}", s),
None => ()
};
*k.borrow_mut() = Some(x);
@ -65,20 +65,20 @@ mod imp {
get(); // check the assertion below
}
pub fn get() -> TaskState {
pub fn get() -> ThreadState {
let state = STATE.with(|ref k| {
match *k.borrow() {
None => panic!("Task state not initialized"),
None => panic!("Thread state not initialized"),
Some(s) => s,
}
});
// Exactly one of the task type flags should be set.
// Exactly one of the thread type flags should be set.
assert_eq!(1, TYPES.iter().filter(|&&ty| state.contains(ty)).count());
state
}
pub fn enter(x: TaskState) {
pub fn enter(x: ThreadState) {
let state = get();
assert!(!state.intersects(x));
STATE.with(|ref k| {
@ -86,7 +86,7 @@ mod imp {
})
}
pub fn exit(x: TaskState) {
pub fn exit(x: ThreadState) {
let state = get();
assert!(state.contains(x));
STATE.with(|ref k| {
@ -97,9 +97,9 @@ mod imp {
#[cfg(not(debug_assertions))]
mod imp {
use super::TaskState;
#[inline(always)] pub fn initialize(_: TaskState) { }
#[inline(always)] pub fn get() -> TaskState { TaskState::empty() }
#[inline(always)] pub fn enter(_: TaskState) { }
#[inline(always)] pub fn exit(_: TaskState) { }
use super::ThreadState;
#[inline(always)] pub fn initialize(_: ThreadState) { }
#[inline(always)] pub fn get() -> ThreadState { ThreadState::empty() }
#[inline(always)] pub fn enter(_: ThreadState) { }
#[inline(always)] pub fn exit(_: ThreadState) { }
}

View file

@ -2,14 +2,14 @@
* 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 task pool.
//! A load-balancing thread pool.
//!
//! This differs in implementation from std::sync::TaskPool in that each job is
//! up for grabs by any of the child tasks in the 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 task 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.
@ -18,27 +18,27 @@
use std::boxed::FnBox;
use std::sync::mpsc::{Receiver, Sender, channel};
use std::sync::{Arc, Mutex};
use task::spawn_named;
use thread::spawn_named;
pub struct TaskPool {
pub struct ThreadPool {
tx: Sender<Box<FnBox() + Send + 'static>>,
}
impl TaskPool {
pub fn new(tasks: u32) -> TaskPool {
assert!(tasks > 0);
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..tasks {
for i in 0..threads {
let state = state.clone();
spawn_named(
format!("TaskPoolWorker {}/{}", i + 1, tasks),
format!("ThreadPoolWorker {}/{}", i + 1, threads),
move || worker(&*state));
}
return TaskPool { tx: tx };
return ThreadPool { tx: tx };
fn worker(rx: &Mutex<Receiver<Box<FnBox() + Send + 'static>>>) {
while let Ok(job) = rx.lock().unwrap().recv() {

View file

@ -10,7 +10,7 @@ static NEXT_TID: AtomicUsize = ATOMIC_USIZE_INIT;
thread_local!(static TASK_LOCAL_TID: Rc<RefCell<Option<usize>>> = Rc::new(RefCell::new(None)));
/// Every task gets one, that's unique.
/// Every thread gets one, that's unique.
pub fn tid() -> usize {
TASK_LOCAL_TID.with(|ref k| {
let ret =

View file

@ -12,8 +12,8 @@ use libc::usleep;
use rand::{Rng, XorShiftRng, weak_rng};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::{Receiver, Sender, channel};
use task::spawn_named;
use task_state;
use thread::spawn_named;
use thread_state;
/// A unit of work.
///
@ -234,8 +234,8 @@ pub struct WorkQueue<QueueData: 'static, WorkData: 'static> {
impl<QueueData: Sync, WorkData: Send> WorkQueue<QueueData, WorkData> {
/// Creates a new work queue and spawns all the threads associated with
/// it.
pub fn new(task_name: &'static str,
state: task_state::TaskState,
pub fn new(thread_name: &'static str,
state: thread_state::ThreadState,
thread_count: usize) -> WorkQueue<QueueData, WorkData> {
// Set up data structures.
let (supervisor_chan, supervisor_port) = channel();
@ -272,9 +272,9 @@ impl<QueueData: Sync, WorkData: Send> WorkQueue<QueueData, WorkData> {
for (i, thread) in threads.into_iter().enumerate() {
spawn_named(
format!("{} worker {}/{}", task_name, i + 1, thread_count),
format!("{} worker {}/{}", thread_name, i + 1, thread_count),
move || {
task_state::initialize(state | task_state::IN_WORKER);
thread_state::initialize(state | thread_state::IN_WORKER);
let mut thread = thread;
thread.start()
})