Skip to content

Commit 0426ef5

Browse files
committed
---
yaml --- r: 144477 b: refs/heads/try2 c: 7f32ea8 h: refs/heads/master i: 144475: 2d88fa3 v: v3
1 parent 4af1283 commit 0426ef5

File tree

12 files changed

+168
-172
lines changed

12 files changed

+168
-172
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: 803f941867d1d68710f211535de69bb30f79f917
8+
refs/heads/try2: 7f32ea8820727f4f4944423133e6b32e2653a1d2
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::UnsafeAtomicRcBox;
47+
use std::unstable::sync::UnsafeArc;
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: UnsafeAtomicRcBox<T> }
111+
pub struct Arc<T> { priv x: UnsafeArc<T> }
112112

113113

114114
/**
@@ -118,7 +118,7 @@ pub struct Arc<T> { priv x: UnsafeAtomicRcBox<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: UnsafeAtomicRcBox::new(data) }
121+
Arc { x: UnsafeArc::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: UnsafeAtomicRcBox<MutexArcInner<T>> }
163+
struct MutexArc<T> { priv x: UnsafeArc<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: UnsafeAtomicRcBox::new(data) }
190+
MutexArc { x: UnsafeArc::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: UnsafeAtomicRcBox<RWArcInner<T>>,
312+
priv x: UnsafeArc<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: UnsafeAtomicRcBox::new(data), }
338+
RWArc { x: UnsafeArc::new(data), }
339339
}
340340
341341
/**

branches/try2/src/libextra/sync.rs

Lines changed: 22 additions & 32 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, UnsafeAtomicRcBox};
24+
use std::unstable::sync::{Exclusive, UnsafeArc};
2525
use std::unstable::atomics;
2626
use std::unstable::finally::Finally;
2727
use std::util;
@@ -135,9 +135,7 @@ impl<Q:Send> Sem<Q> {
135135
do task::unkillable {
136136
do (|| {
137137
self.acquire();
138-
unsafe {
139-
do task::rekillable { blk() }
140-
}
138+
do task::rekillable { blk() }
141139
}).finally {
142140
self.release();
143141
}
@@ -234,10 +232,8 @@ impl<'self> Condvar<'self> {
234232
// signaller already sent -- I mean 'unconditionally' in contrast
235233
// with acquire().)
236234
do (|| {
237-
unsafe {
238-
do task::rekillable {
239-
let _ = WaitEnd.take_unwrap().recv();
240-
}
235+
do task::rekillable {
236+
let _ = WaitEnd.take_unwrap().recv();
241237
}
242238
}).finally {
243239
// Reacquire the condvar. Note this is back in the unkillable
@@ -448,7 +444,7 @@ struct RWLockInner {
448444
pub struct RWLock {
449445
priv order_lock: Semaphore,
450446
priv access_lock: Sem<~[WaitQueue]>,
451-
priv state: UnsafeAtomicRcBox<RWLockInner>,
447+
priv state: UnsafeArc<RWLockInner>,
452448
}
453449

454450
impl RWLock {
@@ -460,7 +456,7 @@ impl RWLock {
460456
* Similar to mutex_with_condvars.
461457
*/
462458
pub fn new_with_condvars(num_condvars: uint) -> RWLock {
463-
let state = UnsafeAtomicRcBox::new(RWLockInner {
459+
let state = UnsafeArc::new(RWLockInner {
464460
read_mode: false,
465461
read_count: atomics::AtomicUint::new(0),
466462
});
@@ -516,14 +512,12 @@ impl RWLock {
516512
* 'write' from other tasks will run concurrently with this one.
517513
*/
518514
pub fn write<U>(&self, blk: &fn() -> U) -> U {
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-
}
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()
527521
}
528522
}
529523
}
@@ -562,16 +556,14 @@ impl RWLock {
562556
// which can't happen until T2 finishes the downgrade-read entirely.
563557
// The astute reader will also note that making waking writers use the
564558
// order_lock is better for not starving readers.
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-
}
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() })
575567
}
576568
}
577569
}
@@ -606,10 +598,8 @@ impl RWLock {
606598
(&self.access_lock).acquire();
607599
(&self.order_lock).release();
608600
do (|| {
609-
unsafe {
610-
do task::rekillable {
611-
blk(RWLockWriteMode { lock: self, token: NonCopyable::new() })
612-
}
601+
do task::rekillable {
602+
blk(RWLockWriteMode { lock: self, token: NonCopyable::new() })
613603
}
614604
}).finally {
615605
let writer_or_last_reader;

branches/try2/src/libstd/option.rs

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

4444
use clone::Clone;
4545
use cmp::{Eq,Ord};
46-
use ops::Add;
4746
use util;
4847
use num::Zero;
4948
use iterator;
@@ -77,18 +76,6 @@ impl<T: Eq + Ord> Ord for Option<T> {
7776
}
7877
}
7978

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-
9279
// FIXME: #8242 implementing manually because deriving doesn't work for some reason
9380
impl<T: ToStr> ToStr for Option<T> {
9481
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::UnsafeAtomicRcBox;
24+
use unstable::sync::UnsafeArc;
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: UnsafeAtomicRcBox<AtomicOption<StreamChanOne<T>>>
570+
priv next: UnsafeArc<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: UnsafeAtomicRcBox::new(next) }
577+
SharedChan { next: UnsafeArc::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: UnsafeAtomicRcBox<AtomicOption<PortOne<StreamPortOne<T>>>>
623+
priv next_link: UnsafeArc<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: UnsafeAtomicRcBox::new(next_link) }
633+
SharedPort { next_link: UnsafeArc::new(next_link) }
634634
}
635635
}
636636

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

Lines changed: 12 additions & 8 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::{UnsafeAtomicRcBox, LittleLock};
162+
use unstable::sync::{UnsafeArc, 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 = UnsafeAtomicRcBox<KillFlag>;
173+
type KillFlagHandle = UnsafeArc<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(UnsafeAtomicRcBox<KillHandleInner>);
214+
pub struct KillHandle(UnsafeArc<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-
UnsafeAtomicRcBox::newN(flag, num_handles)
320+
UnsafeArc::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-
UnsafeAtomicRcBox::new2(KillFlag(AtomicUint::new(KILL_RUNNING)));
384-
let handle = KillHandle(UnsafeAtomicRcBox::new(KillHandleInner {
383+
UnsafeArc::new2(KillFlag(AtomicUint::new(KILL_RUNNING)));
384+
let handle = KillHandle(UnsafeArc::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 UnsafeAtomicRcBox ensure that this write will be seen by the
463+
// in UnsafeArc 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,7 +647,11 @@ 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-
rtassert!(self.unkillable != 0);
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+
}
651655
self.unkillable -= 1;
652656
if self.unkillable == 0 {
653657
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::{UnsafeAtomicRcBox, LittleLock};
19+
use unstable::sync::{UnsafeArc, LittleLock};
2020
use clone::Clone;
2121

2222
pub struct MessageQueue<T> {
23-
priv state: UnsafeAtomicRcBox<State<T>>
23+
priv state: UnsafeArc<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: UnsafeAtomicRcBox::new(State {
35+
state: UnsafeArc::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::UnsafeAtomicRcBox;
77+
use unstable::sync::UnsafeArc;
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 = UnsafeAtomicRcBox::new(AtomicInt::new(0));
314+
let exit_code = UnsafeArc::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::{UnsafeAtomicRcBox, LittleLock};
18+
use unstable::sync::{UnsafeArc, LittleLock};
1919
use rt::sched::SchedHandle;
2020
use clone::Clone;
2121

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

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

0 commit comments

Comments
 (0)