]> git.proxmox.com Git - rustc.git/blob - src/librustc/dep_graph/raii.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / librustc / dep_graph / raii.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use hir::def_id::DefId;
12 use super::DepNode;
13 use super::thread::{DepGraphThreadData, DepMessage};
14
15 pub struct DepTask<'graph> {
16 data: &'graph DepGraphThreadData,
17 key: DepNode<DefId>,
18 }
19
20 impl<'graph> DepTask<'graph> {
21 pub fn new(data: &'graph DepGraphThreadData, key: DepNode<DefId>)
22 -> DepTask<'graph> {
23 data.enqueue(DepMessage::PushTask(key));
24 DepTask { data: data, key: key }
25 }
26 }
27
28 impl<'graph> Drop for DepTask<'graph> {
29 fn drop(&mut self) {
30 self.data.enqueue(DepMessage::PopTask(self.key));
31 }
32 }
33
34 pub struct IgnoreTask<'graph> {
35 data: &'graph DepGraphThreadData
36 }
37
38 impl<'graph> IgnoreTask<'graph> {
39 pub fn new(data: &'graph DepGraphThreadData) -> IgnoreTask<'graph> {
40 data.enqueue(DepMessage::PushIgnore);
41 IgnoreTask { data: data }
42 }
43 }
44
45 impl<'graph> Drop for IgnoreTask<'graph> {
46 fn drop(&mut self) {
47 self.data.enqueue(DepMessage::PopIgnore);
48 }
49 }