From 0761107daa6f32abae0b7446de326fc3d5ee875b Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 28 May 2014 15:32:27 -0700 Subject: [PATCH] Make the workqueue's type parameter names less terrible --- src/components/util/workqueue.rs | 69 ++++++++++++++++---------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/src/components/util/workqueue.rs b/src/components/util/workqueue.rs index a9eeacd63a8..7c28abbb821 100644 --- a/src/components/util/workqueue.rs +++ b/src/components/util/workqueue.rs @@ -18,63 +18,62 @@ use std::task::TaskOpts; /// A unit of work. /// -/// The type parameter `QUD` stands for "queue user data" and represents global custom data for the -/// entire work queue, and the type parameter `WUD` stands for "work user data" and represents -/// custom data specific to each unit of work. -pub struct WorkUnit { +/// # Type parameters +/// +/// - `QueueData`: global custom data for the entire work queue. +/// - `WorkData`: custom data specific to each unit of work. +pub struct WorkUnit { /// The function to execute. - pub fun: extern "Rust" fn(WUD, &mut WorkerProxy), + pub fun: extern "Rust" fn(WorkData, &mut WorkerProxy), /// Arbitrary data. - pub data: WUD, + pub data: WorkData, } /// Messages from the supervisor to the worker. -enum WorkerMsg { +enum WorkerMsg { /// Tells the worker to start work. - StartMsg(Worker>, *mut AtomicUint, *QUD), - + StartMsg(Worker>, *mut AtomicUint, *QueueData), /// Tells the worker to stop. It can be restarted again with a `StartMsg`. StopMsg, - /// Tells the worker thread to terminate. ExitMsg, } /// Messages to the supervisor. -enum SupervisorMsg { +enum SupervisorMsg { FinishedMsg, - ReturnDequeMsg(uint, Worker>), + ReturnDequeMsg(uint, Worker>), } /// Information that the supervisor thread keeps about the worker threads. -struct WorkerInfo { +struct WorkerInfo { /// The communication channel to the workers. - chan: Sender>, + chan: Sender>, /// The buffer pool for this deque. - pool: BufferPool>, + pool: BufferPool>, /// The worker end of the deque, if we have it. - deque: Option>>, + deque: Option>>, /// The thief end of the work-stealing deque. - thief: Stealer>, + thief: Stealer>, } /// Information specific to each worker thread that the thread keeps. -struct WorkerThread { +struct WorkerThread { /// The index of this worker. index: uint, /// The communication port from the supervisor. - port: Receiver>, + port: Receiver>, /// The communication channel on which messages are sent to the supervisor. - chan: Sender>, + chan: Sender>, /// The thief end of the work-stealing deque for all other workers. - other_deques: Vec>>, + other_deques: Vec>>, /// The random number generator for this worker. rng: XorShiftRng, } static SPIN_COUNT: uint = 1000; -impl WorkerThread { +impl WorkerThread { /// The main logic. This function starts up the worker and listens for /// messages. fn start(&mut self) { @@ -160,16 +159,16 @@ impl WorkerThread { } /// A handle to the work queue that individual work units have. -pub struct WorkerProxy<'a,QUD,WUD> { - worker: &'a mut Worker>, +pub struct WorkerProxy<'a, QueueData, WorkData> { + worker: &'a mut Worker>, ref_count: *mut AtomicUint, - queue_data: *QUD, + queue_data: *QueueData, } -impl<'a,QUD,WUD:Send> WorkerProxy<'a,QUD,WUD> { +impl<'a, QueueData, WorkData: Send> WorkerProxy<'a, QueueData, WorkData> { /// Enqueues a block into the work queue. #[inline] - pub fn push(&mut self, work_unit: WorkUnit) { + pub fn push(&mut self, work_unit: WorkUnit) { unsafe { drop((*self.ref_count).fetch_add(1, SeqCst)); } @@ -178,7 +177,7 @@ impl<'a,QUD,WUD:Send> WorkerProxy<'a,QUD,WUD> { /// Retrieves the queue user data. #[inline] - pub fn user_data<'a>(&'a self) -> &'a QUD { + pub fn user_data<'a>(&'a self) -> &'a QueueData { unsafe { cast::transmute(self.queue_data) } @@ -186,21 +185,21 @@ impl<'a,QUD,WUD:Send> WorkerProxy<'a,QUD,WUD> { } /// A work queue on which units of work can be submitted. -pub struct WorkQueue { +pub struct WorkQueue { /// Information about each of the workers. - workers: Vec>, + workers: Vec>, /// A port on which deques can be received from the workers. - port: Receiver>, + port: Receiver>, /// The amount of work that has been enqueued. work_count: uint, /// Arbitrary user data. - pub data: QUD, + pub data: QueueData, } -impl WorkQueue { +impl WorkQueue { /// Creates a new work queue and spawns all the threads associated with /// it. - pub fn new(task_name: &'static str, thread_count: uint, user_data: QUD) -> WorkQueue { + pub fn new(task_name: &'static str, thread_count: uint, user_data: QueueData) -> WorkQueue { // Set up data structures. let (supervisor_chan, supervisor_port) = channel(); let (mut infos, mut threads) = (vec!(), vec!()); @@ -253,7 +252,7 @@ impl WorkQueue { /// Enqueues a block into the work queue. #[inline] - pub fn push(&mut self, work_unit: WorkUnit) { + pub fn push(&mut self, work_unit: WorkUnit) { match self.workers.get_mut(0).deque { None => { fail!("tried to push a block but we don't have the deque?!")