Skip to content

Commit 801316c

Browse files
committed
---
yaml --- r: 151431 b: refs/heads/try2 c: b2c6d6f h: refs/heads/master i: 151429: c0fb9cb 151427: 8bfe044 151423: 8ae3640 v: v3
1 parent ecfd2a9 commit 801316c

File tree

9 files changed

+712
-278
lines changed

9 files changed

+712
-278
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 295e0a04ad57c001e854c5f52cecc18335113544
8+
refs/heads/try2: b2c6d6fd3ff303c2e32a3ac0175810581c65b751
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustuv/access.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct Guard<'a> {
3131
}
3232

3333
struct Inner {
34-
queue: Vec<BlockedTask>,
34+
queue: Vec<(BlockedTask, uint)>,
3535
held: bool,
3636
closed: bool,
3737
}
@@ -47,16 +47,17 @@ impl Access {
4747
}
4848
}
4949

50-
pub fn grant<'a>(&'a mut self, missile: HomingMissile) -> Guard<'a> {
50+
pub fn grant<'a>(&'a mut self, token: uint,
51+
missile: HomingMissile) -> Guard<'a> {
5152
// This unsafety is actually OK because the homing missile argument
5253
// guarantees that we're on the same event loop as all the other objects
5354
// attempting to get access granted.
54-
let inner: &mut Inner = unsafe { cast::transmute(self.inner.get()) };
55+
let inner: &mut Inner = unsafe { &mut *self.inner.get() };
5556

5657
if inner.held {
5758
let t: Box<Task> = Local::take();
5859
t.deschedule(1, |task| {
59-
inner.queue.push(task);
60+
inner.queue.push((task, token));
6061
Ok(())
6162
});
6263
assert!(inner.held);
@@ -75,6 +76,17 @@ impl Access {
7576
// necessary synchronization to be running on this thread.
7677
unsafe { (*self.inner.get()).closed = true; }
7778
}
79+
80+
// Dequeue a blocked task with a specified token. This is unsafe because it
81+
// is only safe to invoke while on the home event loop, and there is no
82+
// guarantee that this i being invoked on the home event loop.
83+
pub unsafe fn dequeue(&mut self, token: uint) -> Option<BlockedTask> {
84+
let inner: &mut Inner = &mut *self.inner.get();
85+
match inner.queue.iter().position(|&(_, t)| t == token) {
86+
Some(i) => Some(inner.queue.remove(i).unwrap().val0()),
87+
None => None,
88+
}
89+
}
7890
}
7991

8092
impl Clone for Access {
@@ -111,9 +123,9 @@ impl<'a> Drop for Guard<'a> {
111123
// scheduled on this scheduler. Because we might be woken up on some
112124
// other scheduler, we drop our homing missile before we reawaken
113125
// the task.
114-
Some(task) => {
126+
Some((task, _)) => {
115127
drop(self.missile.take());
116-
let _ = task.wake().map(|t| t.reawaken());
128+
task.reawaken();
117129
}
118130
None => { inner.held = false; }
119131
}

branches/try2/src/librustuv/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ fn start(argc: int, argv: **u8) -> int {
8484
mod macros;
8585

8686
mod access;
87+
mod timeout;
8788
mod homing;
8889
mod queue;
8990
mod rc;

0 commit comments

Comments
 (0)