(index<- )
./
libstd
/
rt
/
work_queue.rs
1
// Copyright 2013 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
container::Container
;
12
use
option::*
;
13
use
vec::OwnedVector
;
14
use
unstable::sync::Exclusive
;
15
use
cell::Cell
;
16
use
kinds::Send
;
17
use
clone::Clone
;
18
19
pub
struct
WorkQueue
<T>
{
20
// XXX: Another mystery bug fixed by boxing this lock
21
priv
queue:
~
Exclusive<~
[
T
]
>
22
}
23
24
impl
<T:
Send
>
WorkQueue
<
T
>
{
25
pub
fn
new
()
->
WorkQueue<
T
>
{
26
WorkQueue
{
27
queue:
~
Exclusive::new
(
~
[]
)
28
}
29
}
30
31
pub
fn
push
(
&mut self
,
value
:
T
)
{
32
unsafe
{
33
let
value
=
Cell::new
(
value
)
;
34
self.
queue
.with
(
|
q
|
q
.unshift
(
value
.take
())
)
;
35
}
36
}
37
38
pub
fn
pop
(
&mut self
)
->
Option<
T
>
{
39
unsafe
{
40
do
self.
queue
.
with |
q
|
{
41
if
!
q
.is_empty
()
{
42
Some
(
q
.shift
())
43
}
else
{
44
None
45
}
46
}
47
}
48
}
49
50
pub
fn
steal
(
&mut self
)
->
Option<
T
>
{
51
unsafe
{
52
do
self.
queue
.
with |
q
|
{
53
if
!
q
.is_empty
()
{
54
Some
(
q
.pop
())
55
}
else
{
56
None
57
}
58
}
59
}
60
}
61
62
pub
fn is_empty
(
&self
)
->
bool
{
63
unsafe
{
64
self.
queue
.with_imm
(
|
q
|
q
.is_empty
()
)
65
}
66
}
67
}
68
69
impl
<T>
Clone
for
WorkQueue
<
T
>
{
70
fn
clone
(
&self
)
->
WorkQueue<
T
>
{
71
WorkQueue
{
72
queue:
self.
queue
.clone
()
73
}
74
}
75
}
libstd/rt/work_queue.rs:18:1-18:1 -struct- definition:
pub struct WorkQueue<T> {
references:-
26:
WorkQueue {
25:
pub fn new() -> WorkQueue<T> {
70:
fn clone(&self) -> WorkQueue<T> {
71:
WorkQueue {
24:
impl<T: Send> WorkQueue<T> {
69:
impl<T> Clone for WorkQueue<T> {
libstd/rt/mod.rs:
270:
let work_queues: ~[WorkQueue<~Task>] = vec::from_fn(nscheds, |_| WorkQueue::new());
libstd/rt/sched.rs:
111:
work_queue: WorkQueue<~Task>,
124:
work_queues: ~[WorkQueue<~Task>],
43:
priv work_queue: WorkQueue<~Task>,
112:
work_queues: ~[WorkQueue<~Task>],
123:
work_queue: WorkQueue<~Task>,
46:
work_queues: ~[WorkQueue<~Task>],