aboutsummaryrefslogtreecommitdiffstats
path: root/components/util/workqueue.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-07-06 08:29:17 -0600
committerbors-servo <metajack+bors@gmail.com>2015-07-06 08:29:17 -0600
commita3821bf24094bf5bb2a9553e66b69da3b6430aa5 (patch)
treea032c77c25aaafb41899de6755326471b451e053 /components/util/workqueue.rs
parent6386addb01dfec4bda38f99e534516ddf5ff77aa (diff)
parent24730f1078a216c3d32d3efc9c6a7c01b82a1706 (diff)
downloadservo-a3821bf24094bf5bb2a9553e66b69da3b6430aa5.tar.gz
servo-a3821bf24094bf5bb2a9553e66b69da3b6430aa5.zip
Auto merge of #6547 - Ms2ger:workqueue-reference, r=pcwalton
Borrow the QueueData for WorkQueue::run. This allows us to get rid of the raw pointers and unsafe dereferencing in the parallel layout implementation. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6547) <!-- Reviewable:end -->
Diffstat (limited to 'components/util/workqueue.rs')
-rw-r--r--components/util/workqueue.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/components/util/workqueue.rs b/components/util/workqueue.rs
index 6f636f8a007..6d11e814c86 100644
--- a/components/util/workqueue.rs
+++ b/components/util/workqueue.rs
@@ -169,7 +169,10 @@ impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> {
let mut proxy = WorkerProxy {
worker: &mut deque,
ref_count: ref_count,
- queue_data: queue_data,
+ // queue_data is kept alive in the stack frame of
+ // WorkQueue::run until we send the
+ // SupervisorMsg::ReturnDeque message below.
+ queue_data: unsafe { &*queue_data },
worker_index: self.index as u8,
};
(work_unit.fun)(work_unit.data, &mut proxy);
@@ -193,7 +196,7 @@ impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> {
pub struct WorkerProxy<'a, QueueData: 'a, WorkData: 'a> {
worker: &'a mut Worker<WorkUnit<QueueData, WorkData>>,
ref_count: *mut AtomicUsize,
- queue_data: *const QueueData,
+ queue_data: &'a QueueData,
worker_index: u8,
}
@@ -209,10 +212,8 @@ impl<'a, QueueData: 'static, WorkData: Send + 'static> WorkerProxy<'a, QueueData
/// Retrieves the queue user data.
#[inline]
- pub fn user_data<'b>(&'b self) -> &'b QueueData {
- unsafe {
- mem::transmute(self.queue_data)
- }
+ pub fn user_data(&self) -> &'a QueueData {
+ self.queue_data
}
/// Retrieves the index of the worker.
@@ -302,13 +303,13 @@ impl<QueueData: Send, WorkData: Send> WorkQueue<QueueData, WorkData> {
}
/// Synchronously runs all the enqueued tasks and waits for them to complete.
- pub fn run(&mut self, data: QueueData) {
+ pub fn run(&mut self, data: &QueueData) {
// Tell the workers to start.
let mut work_count = AtomicUsize::new(self.work_count);
for worker in self.workers.iter_mut() {
worker.chan.send(WorkerMsg::Start(worker.deque.take().unwrap(),
&mut work_count,
- &data)).unwrap()
+ data)).unwrap()
}
// Wait for the work to finish.