]> git.proxmox.com Git - rustc.git/blame - src/librustc/dep_graph/raii.rs
Imported Upstream version 1.11.0+dfsg1
[rustc.git] / src / librustc / dep_graph / raii.rs
CommitLineData
9cc50fc6
SL
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
54a0048b 11use hir::def_id::DefId;
9cc50fc6
SL
12use super::DepNode;
13use super::thread::{DepGraphThreadData, DepMessage};
14
15pub struct DepTask<'graph> {
16 data: &'graph DepGraphThreadData,
3157f602 17 key: Option<DepNode<DefId>>,
9cc50fc6
SL
18}
19
20impl<'graph> DepTask<'graph> {
54a0048b
SL
21 pub fn new(data: &'graph DepGraphThreadData, key: DepNode<DefId>)
22 -> DepTask<'graph> {
3157f602
XL
23 data.enqueue(DepMessage::PushTask(key.clone()));
24 DepTask { data: data, key: Some(key) }
9cc50fc6
SL
25 }
26}
27
28impl<'graph> Drop for DepTask<'graph> {
29 fn drop(&mut self) {
3157f602 30 self.data.enqueue(DepMessage::PopTask(self.key.take().unwrap()));
9cc50fc6
SL
31 }
32}
33
34pub struct IgnoreTask<'graph> {
35 data: &'graph DepGraphThreadData
36}
37
38impl<'graph> IgnoreTask<'graph> {
39 pub fn new(data: &'graph DepGraphThreadData) -> IgnoreTask<'graph> {
40 data.enqueue(DepMessage::PushIgnore);
41 IgnoreTask { data: data }
42 }
43}
44
45impl<'graph> Drop for IgnoreTask<'graph> {
46 fn drop(&mut self) {
47 self.data.enqueue(DepMessage::PopIgnore);
48 }
49}