Skip to content

Commit 7f69067

Browse files
committed
---
yaml --- r: 144473 b: refs/heads/try2 c: 20567a0 h: refs/heads/master i: 144471: e3f598e v: v3
1 parent 84bb2bc commit 7f69067

File tree

13 files changed

+181
-170
lines changed

13 files changed

+181
-170
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: 3ab0561b00d2993706d11bfbbce4a357110195dd
8+
refs/heads/try2: 20567a0c3c306853180e428f83302add09b5cb8c
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libextra/arc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use sync;
4444
use sync::{Mutex, RWLock};
4545

4646
use std::cast;
47-
use std::unstable::sync::UnsafeArc;
47+
use std::unstable::sync::UnsafeAtomicRcBox;
4848
use std::task;
4949
use std::borrow;
5050

@@ -108,7 +108,7 @@ impl<'self> Condvar<'self> {
108108
****************************************************************************/
109109

110110
/// An atomically reference counted wrapper for shared immutable state.
111-
pub struct Arc<T> { priv x: UnsafeArc<T> }
111+
pub struct Arc<T> { priv x: UnsafeAtomicRcBox<T> }
112112

113113

114114
/**
@@ -118,7 +118,7 @@ pub struct Arc<T> { priv x: UnsafeArc<T> }
118118
impl<T:Freeze+Send> Arc<T> {
119119
/// Create an atomically reference counted wrapper.
120120
pub fn new(data: T) -> Arc<T> {
121-
Arc { x: UnsafeArc::new(data) }
121+
Arc { x: UnsafeAtomicRcBox::new(data) }
122122
}
123123

124124
pub fn get<'a>(&'a self) -> &'a T {
@@ -160,7 +160,7 @@ impl<T:Freeze + Send> Clone for Arc<T> {
160160
#[doc(hidden)]
161161
struct MutexArcInner<T> { priv lock: Mutex, priv failed: bool, priv data: T }
162162
/// An Arc with mutable data protected by a blocking mutex.
163-
struct MutexArc<T> { priv x: UnsafeArc<MutexArcInner<T>> }
163+
struct MutexArc<T> { priv x: UnsafeAtomicRcBox<MutexArcInner<T>> }
164164

165165

166166
impl<T:Send> Clone for MutexArc<T> {
@@ -187,7 +187,7 @@ impl<T:Send> MutexArc<T> {
187187
lock: Mutex::new_with_condvars(num_condvars),
188188
failed: false, data: user_data
189189
};
190-
MutexArc { x: UnsafeArc::new(data) }
190+
MutexArc { x: UnsafeAtomicRcBox::new(data) }
191191
}
192192

193193
/**
@@ -309,7 +309,7 @@ struct RWArcInner<T> { priv lock: RWLock, priv failed: bool, priv data: T }
309309
*/
310310
#[no_freeze]
311311
struct RWArc<T> {
312-
priv x: UnsafeArc<RWArcInner<T>>,
312+
priv x: UnsafeAtomicRcBox<RWArcInner<T>>,
313313
}
314314
315315
impl<T:Freeze + Send> Clone for RWArc<T> {
@@ -335,7 +335,7 @@ impl<T:Freeze + Send> RWArc<T> {
335335
lock: RWLock::new_with_condvars(num_condvars),
336336
failed: false, data: user_data
337337
};
338-
RWArc { x: UnsafeArc::new(data), }
338+
RWArc { x: UnsafeAtomicRcBox::new(data), }
339339
}
340340
341341
/**

branches/try2/src/libextra/sync.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::comm;
2121
use std::comm::SendDeferred;
2222
use std::comm::{GenericPort, Peekable};
2323
use std::task;
24-
use std::unstable::sync::{Exclusive, UnsafeArc};
24+
use std::unstable::sync::{Exclusive, UnsafeAtomicRcBox};
2525
use std::unstable::atomics;
2626
use std::unstable::finally::Finally;
2727
use std::util;
@@ -135,7 +135,9 @@ impl<Q:Send> Sem<Q> {
135135
do task::unkillable {
136136
do (|| {
137137
self.acquire();
138-
do task::rekillable { blk() }
138+
unsafe {
139+
do task::rekillable { blk() }
140+
}
139141
}).finally {
140142
self.release();
141143
}
@@ -232,8 +234,10 @@ impl<'self> Condvar<'self> {
232234
// signaller already sent -- I mean 'unconditionally' in contrast
233235
// with acquire().)
234236
do (|| {
235-
do task::rekillable {
236-
let _ = WaitEnd.take_unwrap().recv();
237+
unsafe {
238+
do task::rekillable {
239+
let _ = WaitEnd.take_unwrap().recv();
240+
}
237241
}
238242
}).finally {
239243
// Reacquire the condvar. Note this is back in the unkillable
@@ -444,7 +448,7 @@ struct RWLockInner {
444448
pub struct RWLock {
445449
priv order_lock: Semaphore,
446450
priv access_lock: Sem<~[WaitQueue]>,
447-
priv state: UnsafeArc<RWLockInner>,
451+
priv state: UnsafeAtomicRcBox<RWLockInner>,
448452
}
449453

450454
impl RWLock {
@@ -456,7 +460,7 @@ impl RWLock {
456460
* Similar to mutex_with_condvars.
457461
*/
458462
pub fn new_with_condvars(num_condvars: uint) -> RWLock {
459-
let state = UnsafeArc::new(RWLockInner {
463+
let state = UnsafeAtomicRcBox::new(RWLockInner {
460464
read_mode: false,
461465
read_count: atomics::AtomicUint::new(0),
462466
});
@@ -512,12 +516,14 @@ impl RWLock {
512516
* 'write' from other tasks will run concurrently with this one.
513517
*/
514518
pub fn write<U>(&self, blk: &fn() -> U) -> U {
515-
do task::unkillable {
516-
(&self.order_lock).acquire();
517-
do (&self.access_lock).access {
518-
(&self.order_lock).release();
519-
do task::rekillable {
520-
blk()
519+
unsafe {
520+
do task::unkillable {
521+
(&self.order_lock).acquire();
522+
do (&self.access_lock).access {
523+
(&self.order_lock).release();
524+
do task::rekillable {
525+
blk()
526+
}
521527
}
522528
}
523529
}
@@ -556,14 +562,16 @@ impl RWLock {
556562
// which can't happen until T2 finishes the downgrade-read entirely.
557563
// The astute reader will also note that making waking writers use the
558564
// order_lock is better for not starving readers.
559-
do task::unkillable {
560-
(&self.order_lock).acquire();
561-
do (&self.access_lock).access_cond |cond| {
562-
(&self.order_lock).release();
563-
do task::rekillable {
564-
let opt_lock = Just(&self.order_lock);
565-
blk(&Condvar { sem: cond.sem, order: opt_lock,
566-
token: NonCopyable::new() })
565+
unsafe {
566+
do task::unkillable {
567+
(&self.order_lock).acquire();
568+
do (&self.access_lock).access_cond |cond| {
569+
(&self.order_lock).release();
570+
do task::rekillable {
571+
let opt_lock = Just(&self.order_lock);
572+
blk(&Condvar { sem: cond.sem, order: opt_lock,
573+
token: NonCopyable::new() })
574+
}
567575
}
568576
}
569577
}
@@ -598,8 +606,10 @@ impl RWLock {
598606
(&self.access_lock).acquire();
599607
(&self.order_lock).release();
600608
do (|| {
601-
do task::rekillable {
602-
blk(RWLockWriteMode { lock: self, token: NonCopyable::new() })
609+
unsafe {
610+
do task::rekillable {
611+
blk(RWLockWriteMode { lock: self, token: NonCopyable::new() })
612+
}
603613
}
604614
}).finally {
605615
let writer_or_last_reader;

branches/try2/src/libstd/option.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ let unwrapped_msg = match msg {
4343

4444
use clone::Clone;
4545
use cmp::{Eq,Ord};
46+
use ops::Add;
4647
use util;
4748
use num::Zero;
4849
use iterator;
@@ -76,6 +77,18 @@ impl<T: Eq + Ord> Ord for Option<T> {
7677
}
7778
}
7879

80+
impl<T: Add<T, T>> Add<Option<T>, Option<T>> for Option<T> {
81+
#[inline]
82+
fn add(&self, other: &Option<T>) -> Option<T> {
83+
match (&*self, &*other) {
84+
(&None, &None) => None,
85+
(_, &None) => None,
86+
(&None, _) => None,
87+
(&Some(ref lhs), &Some(ref rhs)) => Some(*lhs + *rhs)
88+
}
89+
}
90+
}
91+
7992
// FIXME: #8242 implementing manually because deriving doesn't work for some reason
8093
impl<T: ToStr> ToStr for Option<T> {
8194
fn to_str(&self) -> ~str {

branches/try2/src/libstd/rt/comm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rt::local::Local;
2121
use rt::select::{SelectInner, SelectPortInner};
2222
use select::{Select, SelectPort};
2323
use unstable::atomics::{AtomicUint, AtomicOption, Acquire, Relaxed, SeqCst};
24-
use unstable::sync::UnsafeArc;
24+
use unstable::sync::UnsafeAtomicRcBox;
2525
use util::Void;
2626
use comm::{GenericChan, GenericSmartChan, GenericPort, Peekable};
2727
use cell::Cell;
@@ -567,14 +567,14 @@ impl<'self, T> SelectPort<T> for &'self Port<T> { }
567567

568568
pub struct SharedChan<T> {
569569
// Just like Chan, but a shared AtomicOption instead of Cell
570-
priv next: UnsafeArc<AtomicOption<StreamChanOne<T>>>
570+
priv next: UnsafeAtomicRcBox<AtomicOption<StreamChanOne<T>>>
571571
}
572572

573573
impl<T> SharedChan<T> {
574574
pub fn new(chan: Chan<T>) -> SharedChan<T> {
575575
let next = chan.next.take();
576576
let next = AtomicOption::new(~next);
577-
SharedChan { next: UnsafeArc::new(next) }
577+
SharedChan { next: UnsafeAtomicRcBox::new(next) }
578578
}
579579
}
580580

@@ -620,7 +620,7 @@ impl<T> Clone for SharedChan<T> {
620620

621621
pub struct SharedPort<T> {
622622
// The next port on which we will receive the next port on which we will receive T
623-
priv next_link: UnsafeArc<AtomicOption<PortOne<StreamPortOne<T>>>>
623+
priv next_link: UnsafeAtomicRcBox<AtomicOption<PortOne<StreamPortOne<T>>>>
624624
}
625625

626626
impl<T> SharedPort<T> {
@@ -630,7 +630,7 @@ impl<T> SharedPort<T> {
630630
let (next_link_port, next_link_chan) = oneshot();
631631
next_link_chan.send(next_data_port);
632632
let next_link = AtomicOption::new(~next_link_port);
633-
SharedPort { next_link: UnsafeArc::new(next_link) }
633+
SharedPort { next_link: UnsafeAtomicRcBox::new(next_link) }
634634
}
635635
}
636636

branches/try2/src/libstd/rt/kill.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ use rt::task::Task;
159159
use task::spawn::Taskgroup;
160160
use to_bytes::IterBytes;
161161
use unstable::atomics::{AtomicUint, Relaxed};
162-
use unstable::sync::{UnsafeArc, LittleLock};
162+
use unstable::sync::{UnsafeAtomicRcBox, LittleLock};
163163
use util;
164164

165165
static KILLED_MSG: &'static str = "killed by linked failure";
@@ -170,7 +170,7 @@ static KILL_KILLED: uint = 1;
170170
static KILL_UNKILLABLE: uint = 2;
171171

172172
struct KillFlag(AtomicUint);
173-
type KillFlagHandle = UnsafeArc<KillFlag>;
173+
type KillFlagHandle = UnsafeAtomicRcBox<KillFlag>;
174174

175175
/// A handle to a blocked task. Usually this means having the ~Task pointer by
176176
/// ownership, but if the task is killable, a killer can steal it at any time.
@@ -211,7 +211,7 @@ struct KillHandleInner {
211211

212212
/// State shared between tasks used for task killing during linked failure.
213213
#[deriving(Clone)]
214-
pub struct KillHandle(UnsafeArc<KillHandleInner>);
214+
pub struct KillHandle(UnsafeAtomicRcBox<KillHandleInner>);
215215

216216
/// Per-task state related to task death, killing, failure, etc.
217217
pub struct Death {
@@ -317,7 +317,7 @@ impl BlockedTask {
317317
let handles = match self {
318318
Unkillable(task) => {
319319
let flag = unsafe { KillFlag(AtomicUint::new(cast::transmute(task))) };
320-
UnsafeArc::newN(flag, num_handles)
320+
UnsafeAtomicRcBox::newN(flag, num_handles)
321321
}
322322
Killable(flag_arc) => flag_arc.cloneN(num_handles),
323323
};
@@ -380,8 +380,8 @@ impl Eq for KillHandle {
380380
impl KillHandle {
381381
pub fn new() -> (KillHandle, KillFlagHandle) {
382382
let (flag, flag_clone) =
383-
UnsafeArc::new2(KillFlag(AtomicUint::new(KILL_RUNNING)));
384-
let handle = KillHandle(UnsafeArc::new(KillHandleInner {
383+
UnsafeAtomicRcBox::new2(KillFlag(AtomicUint::new(KILL_RUNNING)));
384+
let handle = KillHandle(UnsafeAtomicRcBox::new(KillHandleInner {
385385
// Linked failure fields
386386
killed: flag,
387387
unkillable: AtomicUint::new(KILL_RUNNING),
@@ -460,7 +460,7 @@ impl KillHandle {
460460
pub fn notify_immediate_failure(&mut self) {
461461
// A benign data race may happen here if there are failing sibling
462462
// tasks that were also spawned-watched. The refcount's write barriers
463-
// in UnsafeArc ensure that this write will be seen by the
463+
// in UnsafeAtomicRcBox ensure that this write will be seen by the
464464
// unwrapper/destructor, whichever task may unwrap it.
465465
unsafe { (*self.get()).any_child_failed = true; }
466466
}
@@ -647,11 +647,7 @@ impl Death {
647647
/// All calls must be paired with a preceding call to inhibit_kill.
648648
#[inline]
649649
pub fn allow_kill(&mut self, already_failing: bool) {
650-
if self.unkillable == 0 {
651-
// we need to decrement the counter before failing.
652-
self.unkillable -= 1;
653-
fail!("Cannot enter a rekillable() block without a surrounding unkillable()");
654-
}
650+
rtassert!(self.unkillable != 0);
655651
self.unkillable -= 1;
656652
if self.unkillable == 0 {
657653
rtassert!(self.kill_handle.is_some());

branches/try2/src/libstd/rt/message_queue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use kinds::Send;
1616
use vec::OwnedVector;
1717
use cell::Cell;
1818
use option::*;
19-
use unstable::sync::{UnsafeArc, LittleLock};
19+
use unstable::sync::{UnsafeAtomicRcBox, LittleLock};
2020
use clone::Clone;
2121

2222
pub struct MessageQueue<T> {
23-
priv state: UnsafeArc<State<T>>
23+
priv state: UnsafeAtomicRcBox<State<T>>
2424
}
2525

2626
struct State<T> {
@@ -32,7 +32,7 @@ struct State<T> {
3232
impl<T: Send> MessageQueue<T> {
3333
pub fn new() -> MessageQueue<T> {
3434
MessageQueue {
35-
state: UnsafeArc::new(State {
35+
state: UnsafeAtomicRcBox::new(State {
3636
count: 0,
3737
queue: ~[],
3838
lock: LittleLock::new()

branches/try2/src/libstd/rt/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use rt::thread::Thread;
7474
use rt::work_queue::WorkQueue;
7575
use rt::uv::uvio::UvEventLoop;
7676
use unstable::atomics::{AtomicInt, SeqCst};
77-
use unstable::sync::UnsafeArc;
77+
use unstable::sync::UnsafeAtomicRcBox;
7878
use vec::{OwnedVector, MutableVector};
7979

8080
/// The global (exchange) heap.
@@ -311,7 +311,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
311311

312312
// Create a shared cell for transmitting the process exit
313313
// code from the main task to this function.
314-
let exit_code = UnsafeArc::new(AtomicInt::new(0));
314+
let exit_code = UnsafeAtomicRcBox::new(AtomicInt::new(0));
315315
let exit_code_clone = exit_code.clone();
316316

317317
// When the main task exits, after all the tasks in the main

branches/try2/src/libstd/rt/sleeper_list.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ use container::Container;
1515
use vec::OwnedVector;
1616
use option::{Option, Some, None};
1717
use cell::Cell;
18-
use unstable::sync::{UnsafeArc, LittleLock};
18+
use unstable::sync::{UnsafeAtomicRcBox, LittleLock};
1919
use rt::sched::SchedHandle;
2020
use clone::Clone;
2121

2222
pub struct SleeperList {
23-
priv state: UnsafeArc<State>
23+
priv state: UnsafeAtomicRcBox<State>
2424
}
2525

2626
struct State {
@@ -32,7 +32,7 @@ struct State {
3232
impl SleeperList {
3333
pub fn new() -> SleeperList {
3434
SleeperList {
35-
state: UnsafeArc::new(State {
35+
state: UnsafeAtomicRcBox::new(State {
3636
count: 0,
3737
stack: ~[],
3838
lock: LittleLock::new()

0 commit comments

Comments
 (0)