Skip to content

Register new snapshots #10135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/libextra/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ impl<A:Clone> Future<A> {

impl<A> Future<A> {
/// Gets the value from this future, forcing evaluation.
pub fn unwrap(self) -> A {
let mut this = self;
this.get_ref();
let state = replace(&mut this.state, Evaluating);
pub fn unwrap(mut self) -> A {
self.get_ref();
let state = replace(&mut self.state, Evaluating);
match state {
Forced(v) => v,
_ => fail!( "Logic error." ),
Expand Down
40 changes: 17 additions & 23 deletions src/libstd/rt/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<T> ChanOne<T> {

// 'do_resched' configures whether the scheduler immediately switches to
// the receiving task, or leaves the sending task still running.
fn try_send_inner(self, val: T, do_resched: bool) -> bool {
fn try_send_inner(mut self, val: T, do_resched: bool) -> bool {
if do_resched {
rtassert!(!rt::in_sched_context());
}
Expand All @@ -129,9 +129,8 @@ impl<T> ChanOne<T> {
sched.maybe_yield();
}

let mut this = self;
let mut recvr_active = true;
let packet = this.packet();
let packet = self.packet();

unsafe {

Expand All @@ -150,15 +149,15 @@ impl<T> ChanOne<T> {
// done with the packet. NB: In case of do_resched, this *must*
// happen before waking up a blocked task (or be unkillable),
// because we might get a kill signal during the reschedule.
this.suppress_finalize = true;
self.suppress_finalize = true;

match oldstate {
STATE_BOTH => {
// Port is not waiting yet. Nothing to do
}
STATE_ONE => {
// Port has closed. Need to clean up.
let _packet: ~Packet<T> = cast::transmute(this.void_packet);
let _packet: ~Packet<T> = cast::transmute(self.void_packet);
recvr_active = false;
}
task_as_state => {
Expand Down Expand Up @@ -202,22 +201,20 @@ impl<T> PortOne<T> {
}

/// As `recv`, but returns `None` if the send end is closed rather than failing.
pub fn try_recv(self) -> Option<T> {
let mut this = self;

pub fn try_recv(mut self) -> Option<T> {
// Optimistic check. If data was sent already, we don't even need to block.
// No release barrier needed here; we're not handing off our task pointer yet.
if !this.optimistic_check() {
if !self.optimistic_check() {
// No data available yet.
// Switch to the scheduler to put the ~Task into the Packet state.
let sched: ~Scheduler = Local::take();
do sched.deschedule_running_task_and_then |sched, task| {
this.block_on(sched, task);
self.block_on(sched, task);
}
}

// Task resumes.
this.recv_ready()
self.recv_ready()
}
}

Expand Down Expand Up @@ -325,9 +322,8 @@ impl<T> SelectInner for PortOne<T> {
impl<T> Select for PortOne<T> { }

impl<T> SelectPortInner<T> for PortOne<T> {
fn recv_ready(self) -> Option<T> {
let mut this = self;
let packet = this.packet();
fn recv_ready(mut self) -> Option<T> {
let packet = self.packet();

// No further memory barrier is needed here to access the
// payload. Some scenarios:
Expand All @@ -348,9 +344,9 @@ impl<T> SelectPortInner<T> for PortOne<T> {
let payload = (*packet).payload.take();

// The sender has closed up shop. Drop the packet.
let _packet: ~Packet<T> = cast::transmute(this.void_packet);
let _packet: ~Packet<T> = cast::transmute(self.void_packet);
// Suppress the synchronizing actions in the finalizer. We're done with the packet.
this.suppress_finalize = true;
self.suppress_finalize = true;
return payload;
}
}
Expand Down Expand Up @@ -378,18 +374,17 @@ impl<T> Drop for ChanOne<T> {
if self.suppress_finalize { return }

unsafe {
let this = cast::transmute_mut(self);
let oldstate = (*this.packet()).state.swap(STATE_ONE, SeqCst);
let oldstate = (*self.packet()).state.swap(STATE_ONE, SeqCst);
match oldstate {
STATE_BOTH => {
// Port still active. It will destroy the Packet.
},
STATE_ONE => {
let _packet: ~Packet<T> = cast::transmute(this.void_packet);
let _packet: ~Packet<T> = cast::transmute(self.void_packet);
},
task_as_state => {
// The port is blocked waiting for a message we will never send. Wake it.
rtassert!((*this.packet()).payload.is_none());
rtassert!((*self.packet()).payload.is_none());
let recvr = BlockedTask::cast_from_uint(task_as_state);
do recvr.wake().map |woken_task| {
Scheduler::run_task(woken_task);
Expand All @@ -406,14 +401,13 @@ impl<T> Drop for PortOne<T> {
if self.suppress_finalize { return }

unsafe {
let this = cast::transmute_mut(self);
let oldstate = (*this.packet()).state.swap(STATE_ONE, SeqCst);
let oldstate = (*self.packet()).state.swap(STATE_ONE, SeqCst);
match oldstate {
STATE_BOTH => {
// Chan still active. It will destroy the packet.
},
STATE_ONE => {
let _packet: ~Packet<T> = cast::transmute(this.void_packet);
let _packet: ~Packet<T> = cast::transmute(self.void_packet);
}
task_as_state => {
// This case occurs during unwinding, when the blocked
Expand Down
Loading