Skip to content

Commit 3ab0561

Browse files
committed
auto merge of #8790 : huonw/rust/unsafearc, r=thestinger
`UnsafeAtomicRcBox` → `UnsafeArc` (#7674), and `AtomicRcBoxData` → `ArcData` to reflect this. Also, the inner pointer of `UnsafeArc` is now `*mut ArcData`, which avoids some transmutes to `~`: i.e. less chance of mistakes.
2 parents c822d10 + a795755 commit 3ab0561

File tree

8 files changed

+80
-85
lines changed

8 files changed

+80
-85
lines changed

src/libextra/arc.rs

+7-7
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
/**

src/libextra/sync.rs

+3-3
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;
@@ -444,7 +444,7 @@ struct RWLockInner {
444444
pub struct RWLock {
445445
priv order_lock: Semaphore,
446446
priv access_lock: Sem<~[WaitQueue]>,
447-
priv state: UnsafeAtomicRcBox<RWLockInner>,
447+
priv state: UnsafeArc<RWLockInner>,
448448
}
449449

450450
impl RWLock {
@@ -456,7 +456,7 @@ impl RWLock {
456456
* Similar to mutex_with_condvars.
457457
*/
458458
pub fn new_with_condvars(num_condvars: uint) -> RWLock {
459-
let state = UnsafeAtomicRcBox::new(RWLockInner {
459+
let state = UnsafeArc::new(RWLockInner {
460460
read_mode: false,
461461
read_count: atomics::AtomicUint::new(0),
462462
});

src/libstd/rt/comm.rs

+5-5
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

src/libstd/rt/kill.rs

+7-7
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
}

src/libstd/rt/message_queue.rs

+3-3
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()

src/libstd/rt/mod.rs

+2-2
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

src/libstd/rt/sleeper_list.rs

+3-3
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)