Skip to content

Commit 1f51301

Browse files
committed
green: de-~[].
1 parent 7f402ba commit 1f51301

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

src/libgreen/basic.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,30 @@ pub fn event_loop() -> ~EventLoop:Send {
2727
}
2828

2929
struct BasicLoop {
30-
work: ~[proc():Send], // pending work
30+
work: Vec<proc():Send>, // pending work
3131
idle: Option<*mut BasicPausable>, // only one is allowed
32-
remotes: ~[(uint, ~Callback:Send)],
32+
remotes: Vec<(uint, ~Callback:Send)>,
3333
next_remote: uint,
34-
messages: Exclusive<~[Message]>,
34+
messages: Exclusive<Vec<Message>>,
3535
}
3636

3737
enum Message { RunRemote(uint), RemoveRemote(uint) }
3838

3939
impl BasicLoop {
4040
fn new() -> BasicLoop {
4141
BasicLoop {
42-
work: ~[],
42+
work: vec![],
4343
idle: None,
4444
next_remote: 0,
45-
remotes: ~[],
46-
messages: Exclusive::new(~[]),
45+
remotes: vec![],
46+
messages: Exclusive::new(vec![]),
4747
}
4848
}
4949

5050
/// Process everything in the work queue (continually)
5151
fn work(&mut self) {
5252
while self.work.len() > 0 {
53-
for work in replace(&mut self.work, ~[]).move_iter() {
53+
for work in replace(&mut self.work, vec![]).move_iter() {
5454
work();
5555
}
5656
}
@@ -60,7 +60,7 @@ impl BasicLoop {
6060
let messages = unsafe {
6161
self.messages.with(|messages| {
6262
if messages.len() > 0 {
63-
Some(replace(messages, ~[]))
63+
Some(replace(messages, vec![]))
6464
} else {
6565
None
6666
}
@@ -165,12 +165,12 @@ impl EventLoop for BasicLoop {
165165
}
166166

167167
struct BasicRemote {
168-
queue: Exclusive<~[Message]>,
168+
queue: Exclusive<Vec<Message>>,
169169
id: uint,
170170
}
171171

172172
impl BasicRemote {
173-
fn new(queue: Exclusive<~[Message]>, id: uint) -> BasicRemote {
173+
fn new(queue: Exclusive<Vec<Message>>, id: uint) -> BasicRemote {
174174
BasicRemote { queue: queue, id: id }
175175
}
176176
}

src/libgreen/lib.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
// NB this does *not* include globs, please keep it that way.
196196
#![feature(macro_rules, phase)]
197197
#![allow(visible_private_types)]
198+
#![deny(deprecated_owned_vector)]
198199

199200
#[cfg(test)] #[phase(syntax, link)] extern crate log;
200201
#[cfg(test)] extern crate rustuv;
@@ -209,7 +210,6 @@ use std::rt;
209210
use std::sync::atomics::{SeqCst, AtomicUint, INIT_ATOMIC_UINT};
210211
use std::sync::deque;
211212
use std::task::TaskOpts;
212-
use std::slice;
213213
use std::sync::arc::UnsafeArc;
214214

215215
use sched::{Shutdown, Scheduler, SchedHandle, TaskFromFriend, NewNeighbor};
@@ -318,9 +318,9 @@ impl PoolConfig {
318318
/// used to keep the pool alive and also reap the status from the pool.
319319
pub struct SchedPool {
320320
id: uint,
321-
threads: ~[Thread<()>],
322-
handles: ~[SchedHandle],
323-
stealers: ~[deque::Stealer<~task::GreenTask>],
321+
threads: Vec<Thread<()>>,
322+
handles: Vec<SchedHandle>,
323+
stealers: Vec<deque::Stealer<~task::GreenTask>>,
324324
next_friend: uint,
325325
stack_pool: StackPool,
326326
deque_pool: deque::BufferPool<~task::GreenTask>,
@@ -356,9 +356,9 @@ impl SchedPool {
356356
// The pool of schedulers that will be returned from this function
357357
let (p, state) = TaskState::new();
358358
let mut pool = SchedPool {
359-
threads: ~[],
360-
handles: ~[],
361-
stealers: ~[],
359+
threads: vec![],
360+
handles: vec![],
361+
stealers: vec![],
362362
id: unsafe { POOL_ID.fetch_add(1, SeqCst) },
363363
sleepers: SleeperList::new(),
364364
stack_pool: StackPool::new(),
@@ -371,8 +371,14 @@ impl SchedPool {
371371

372372
// Create a work queue for each scheduler, ntimes. Create an extra
373373
// for the main thread if that flag is set. We won't steal from it.
374-
let arr = slice::from_fn(nscheds, |_| pool.deque_pool.deque());
375-
let (workers, stealers) = slice::unzip(arr.move_iter());
374+
let mut workers = Vec::with_capacity(nscheds);
375+
let mut stealers = Vec::with_capacity(nscheds);
376+
377+
for _ in range(0, nscheds) {
378+
let (w, s) = pool.deque_pool.deque();
379+
workers.push(w);
380+
stealers.push(s);
381+
}
376382
pool.stealers = stealers;
377383

378384
// Now that we've got all our work queues, create one scheduler per
@@ -420,7 +426,7 @@ impl SchedPool {
420426
}
421427

422428
// Jettison the task away!
423-
self.handles[idx].send(TaskFromFriend(task));
429+
self.handles.get_mut(idx).send(TaskFromFriend(task));
424430
}
425431

426432
/// Spawns a new scheduler into this M:N pool. A handle is returned to the
@@ -466,7 +472,7 @@ impl SchedPool {
466472
/// This only waits for all tasks in *this pool* of schedulers to exit, any
467473
/// native tasks or extern pools will not be waited on
468474
pub fn shutdown(mut self) {
469-
self.stealers = ~[];
475+
self.stealers = vec![];
470476

471477
// Wait for everyone to exit. We may have reached a 0-task count
472478
// multiple times in the past, meaning there could be several buffered
@@ -478,10 +484,10 @@ impl SchedPool {
478484
}
479485

480486
// Now that everyone's gone, tell everything to shut down.
481-
for mut handle in replace(&mut self.handles, ~[]).move_iter() {
487+
for mut handle in replace(&mut self.handles, vec![]).move_iter() {
482488
handle.send(Shutdown);
483489
}
484-
for thread in replace(&mut self.threads, ~[]).move_iter() {
490+
for thread in replace(&mut self.threads, vec![]).move_iter() {
485491
thread.join();
486492
}
487493
}

src/libgreen/sched.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub struct Scheduler {
4949
work_queue: deque::Worker<~GreenTask>,
5050
/// Work queues for the other schedulers. These are created by
5151
/// cloning the core work queues.
52-
work_queues: ~[deque::Stealer<~GreenTask>],
52+
work_queues: Vec<deque::Stealer<~GreenTask>>,
5353
/// The queue of incoming messages from other schedulers.
5454
/// These are enqueued by SchedHandles after which a remote callback
5555
/// is triggered to handle the message.
@@ -125,7 +125,7 @@ impl Scheduler {
125125
pub fn new(pool_id: uint,
126126
event_loop: ~EventLoop:Send,
127127
work_queue: deque::Worker<~GreenTask>,
128-
work_queues: ~[deque::Stealer<~GreenTask>],
128+
work_queues: Vec<deque::Stealer<~GreenTask>>,
129129
sleeper_list: SleeperList,
130130
state: TaskState)
131131
-> Scheduler {
@@ -138,7 +138,7 @@ impl Scheduler {
138138
pub fn new_special(pool_id: uint,
139139
event_loop: ~EventLoop:Send,
140140
work_queue: deque::Worker<~GreenTask>,
141-
work_queues: ~[deque::Stealer<~GreenTask>],
141+
work_queues: Vec<deque::Stealer<~GreenTask>>,
142142
sleeper_list: SleeperList,
143143
run_anything: bool,
144144
friend: Option<SchedHandle>,
@@ -502,7 +502,7 @@ impl Scheduler {
502502
let len = work_queues.len();
503503
let start_index = self.rng.gen_range(0, len);
504504
for index in range(0, len).map(|i| (i + start_index) % len) {
505-
match work_queues[index].steal() {
505+
match work_queues.get_mut(index).steal() {
506506
deque::Data(task) => {
507507
rtdebug!("found task by stealing");
508508
return Some(task)
@@ -1137,7 +1137,7 @@ mod test {
11371137
let mut pool = BufferPool::new();
11381138
let (normal_worker, normal_stealer) = pool.deque();
11391139
let (special_worker, special_stealer) = pool.deque();
1140-
let queues = ~[normal_stealer, special_stealer];
1140+
let queues = vec![normal_stealer, special_stealer];
11411141
let (_p, state) = TaskState::new();
11421142

11431143
// Our normal scheduler
@@ -1326,7 +1326,7 @@ mod test {
13261326
#[test]
13271327
fn multithreading() {
13281328
run(proc() {
1329-
let mut rxs = ~[];
1329+
let mut rxs = vec![];
13301330
for _ in range(0, 10) {
13311331
let (tx, rx) = channel();
13321332
spawn(proc() {

src/libgreen/stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ impl Drop for Stack {
126126
pub struct StackPool {
127127
// Ideally this would be some datastructure that preserved ordering on
128128
// Stack.min_size.
129-
stacks: ~[Stack],
129+
stacks: Vec<Stack>,
130130
}
131131

132132
impl StackPool {
133133
pub fn new() -> StackPool {
134134
StackPool {
135-
stacks: ~[],
135+
stacks: vec![],
136136
}
137137
}
138138

0 commit comments

Comments
 (0)