Skip to content

Commit c31a88c

Browse files
committed
De-export the submodules of task. Part of #3583.
1 parent 4101d8c commit c31a88c

File tree

6 files changed

+55
-61
lines changed

6 files changed

+55
-61
lines changed

src/libcore/core.rc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,11 @@ mod send_map;
216216

217217
// Concurrency
218218
mod comm;
219-
#[legacy_exports]
220219
mod task {
221-
#[legacy_exports];
222-
#[legacy_exports]
223-
mod local_data;
224-
#[legacy_exports]
220+
pub mod local_data;
225221
mod local_data_priv;
226-
#[legacy_exports]
227-
mod spawn;
228-
#[legacy_exports]
229-
mod rt;
222+
pub mod spawn;
223+
pub mod rt;
230224
}
231225
mod future;
232226
mod pipes;

src/libcore/rt.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ use libc::uintptr_t;
1111
use gc::{cleanup_stack_for_failure, gc, Word};
1212

1313
#[allow(non_camel_case_types)]
14-
type rust_task = c_void;
14+
pub type rust_task = c_void;
1515

1616
extern mod rustrt {
17-
#[legacy_exports];
1817
#[rust_stack]
1918
fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t);
2019

@@ -35,13 +34,13 @@ extern mod rustrt {
3534
// 'rt_', otherwise the compiler won't find it. To fix this, see
3635
// gather_rust_rtcalls.
3736
#[rt(fail_)]
38-
fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) {
37+
pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) {
3938
cleanup_stack_for_failure();
4039
rustrt::rust_upcall_fail(expr, file, line);
4140
}
4241

4342
#[rt(fail_bounds_check)]
44-
fn rt_fail_bounds_check(file: *c_char, line: size_t,
43+
pub fn rt_fail_bounds_check(file: *c_char, line: size_t,
4544
index: size_t, len: size_t) {
4645
let msg = fmt!("index out of bounds: the len is %d but the index is %d",
4746
len as int, index as int);
@@ -51,28 +50,28 @@ fn rt_fail_bounds_check(file: *c_char, line: size_t,
5150
}
5251

5352
#[rt(exchange_malloc)]
54-
fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
53+
pub fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
5554
return rustrt::rust_upcall_exchange_malloc(td, size);
5655
}
5756

5857
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
5958
// inside a landing pad may corrupt the state of the exception handler. If a
6059
// problem occurs, call exit instead.
6160
#[rt(exchange_free)]
62-
fn rt_exchange_free(ptr: *c_char) {
61+
pub fn rt_exchange_free(ptr: *c_char) {
6362
rustrt::rust_upcall_exchange_free(ptr);
6463
}
6564

6665
#[rt(malloc)]
67-
fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
66+
pub fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
6867
return rustrt::rust_upcall_malloc(td, size);
6968
}
7069

7170
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
7271
// inside a landing pad may corrupt the state of the exception handler. If a
7372
// problem occurs, call exit instead.
7473
#[rt(free)]
75-
fn rt_free(ptr: *c_char) {
74+
pub fn rt_free(ptr: *c_char) {
7675
rustrt::rust_upcall_free(ptr);
7776
}
7877

src/libcore/task/local_data_priv.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use local_data::LocalDataKey;
44
use rt::rust_task;
55

6-
trait LocalData { }
6+
pub trait LocalData { }
77
impl<T: Owned> @T: LocalData { }
88

99
impl LocalData: Eq {
@@ -17,19 +17,19 @@ impl LocalData: Eq {
1717

1818
// We use dvec because it's the best data structure in core. If TLS is used
1919
// heavily in future, this could be made more efficient with a proper map.
20-
type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData);
20+
pub type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData);
2121
// Has to be a pointer at outermost layer; the foreign call returns void *.
22-
type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>;
22+
pub type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>;
2323

24-
extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe {
24+
pub extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe {
2525
assert !map_ptr.is_null();
2626
// Get and keep the single reference that was created at the beginning.
2727
let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr);
2828
// All local_data will be destroyed along with the map.
2929
}
3030

3131
// Gets the map from the runtime. Lazily initialises if not done so already.
32-
unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
32+
pub unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
3333

3434
// Relies on the runtime initialising the pointer to null.
3535
// NOTE: The map's box lives in TLS invisibly referenced once. Each time
@@ -52,7 +52,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
5252
}
5353
}
5454

55-
unsafe fn key_to_key_value<T: Owned>(
55+
pub unsafe fn key_to_key_value<T: Owned>(
5656
key: LocalDataKey<T>) -> *libc::c_void {
5757

5858
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
@@ -62,7 +62,7 @@ unsafe fn key_to_key_value<T: Owned>(
6262
}
6363

6464
// If returning Some(..), returns with @T with the map's reference. Careful!
65-
unsafe fn local_data_lookup<T: Owned>(
65+
pub unsafe fn local_data_lookup<T: Owned>(
6666
map: TaskLocalMap, key: LocalDataKey<T>)
6767
-> Option<(uint, *libc::c_void)> {
6868

@@ -80,7 +80,7 @@ unsafe fn local_data_lookup<T: Owned>(
8080
}
8181
}
8282

83-
unsafe fn local_get_helper<T: Owned>(
83+
pub unsafe fn local_get_helper<T: Owned>(
8484
task: *rust_task, key: LocalDataKey<T>,
8585
do_pop: bool) -> Option<@T> {
8686

@@ -102,21 +102,21 @@ unsafe fn local_get_helper<T: Owned>(
102102
}
103103

104104

105-
unsafe fn local_pop<T: Owned>(
105+
pub unsafe fn local_pop<T: Owned>(
106106
task: *rust_task,
107107
key: LocalDataKey<T>) -> Option<@T> {
108108

109109
local_get_helper(task, key, true)
110110
}
111111

112-
unsafe fn local_get<T: Owned>(
112+
pub unsafe fn local_get<T: Owned>(
113113
task: *rust_task,
114114
key: LocalDataKey<T>) -> Option<@T> {
115115

116116
local_get_helper(task, key, false)
117117
}
118118

119-
unsafe fn local_set<T: Owned>(
119+
pub unsafe fn local_set<T: Owned>(
120120
task: *rust_task, key: LocalDataKey<T>, data: @T) {
121121

122122
let map = get_task_local_map(task);
@@ -148,7 +148,7 @@ unsafe fn local_set<T: Owned>(
148148
}
149149
}
150150

151-
unsafe fn local_modify<T: Owned>(
151+
pub unsafe fn local_modify<T: Owned>(
152152
task: *rust_task, key: LocalDataKey<T>,
153153
modify_fn: fn(Option<@T>) -> Option<@T>) {
154154

src/libcore/task/rt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ The task interface to the runtime
77
#[doc(hidden)]; // FIXME #3538
88

99
#[allow(non_camel_case_types)] // runtime type
10-
type sched_id = int;
10+
pub type sched_id = int;
1111
#[allow(non_camel_case_types)] // runtime type
12-
type task_id = int;
12+
pub type task_id = int;
1313

1414
// These are both opaque runtime/compiler types that we don't know the
1515
// structure of and should only deal with via unsafe pointer
1616
#[allow(non_camel_case_types)] // runtime type
17-
type rust_task = libc::c_void;
17+
pub type rust_task = libc::c_void;
1818
#[allow(non_camel_case_types)] // runtime type
19-
type rust_closure = libc::c_void;
19+
pub type rust_closure = libc::c_void;
2020

2121
extern {
2222
#[rust_stack]

src/libcore/task/spawn.rs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,38 @@ macro_rules! move_it (
6969
{ $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); move y } }
7070
)
7171

72-
type TaskSet = send_map::linear::LinearMap<*rust_task,()>;
72+
pub type TaskSet = send_map::linear::LinearMap<*rust_task,()>;
7373

74-
fn new_taskset() -> TaskSet {
74+
pub fn new_taskset() -> TaskSet {
7575
send_map::linear::LinearMap()
7676
}
77-
fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) {
77+
pub fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) {
7878
let didnt_overwrite = tasks.insert(task, ());
7979
assert didnt_overwrite;
8080
}
81-
fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) {
81+
pub fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) {
8282
let was_present = tasks.remove(&task);
8383
assert was_present;
8484
}
85-
fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) {
85+
pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) {
8686
tasks.each_key(|k| blk(*k))
8787
}
8888

8989
// One of these per group of linked-failure tasks.
90-
type TaskGroupData = {
90+
pub type TaskGroupData = {
9191
// All tasks which might kill this group. When this is empty, the group
9292
// can be "GC"ed (i.e., its link in the ancestor list can be removed).
9393
mut members: TaskSet,
9494
// All tasks unidirectionally supervised by (directly or transitively)
9595
// tasks in this group.
9696
mut descendants: TaskSet,
9797
};
98-
type TaskGroupArc = private::Exclusive<Option<TaskGroupData>>;
98+
pub type TaskGroupArc = private::Exclusive<Option<TaskGroupData>>;
9999

100-
type TaskGroupInner = &mut Option<TaskGroupData>;
100+
pub type TaskGroupInner = &mut Option<TaskGroupData>;
101101

102102
// A taskgroup is 'dead' when nothing can cause it to fail; only members can.
103-
pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
103+
pub pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
104104
(&tg.members).is_empty()
105105
}
106106

@@ -111,7 +111,7 @@ pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
111111
// taskgroup which was spawned-unlinked. Tasks from intermediate generations
112112
// have references to the middle of the list; when intermediate generations
113113
// die, their node in the list will be collected at a descendant's spawn-time.
114-
type AncestorNode = {
114+
pub type AncestorNode = {
115115
// Since the ancestor list is recursive, we end up with references to
116116
// exclusives within other exclusives. This is dangerous business (if
117117
// circular references arise, deadlock and memory leaks are imminent).
@@ -124,16 +124,16 @@ type AncestorNode = {
124124
// Recursive rest of the list.
125125
mut ancestors: AncestorList,
126126
};
127-
enum AncestorList = Option<private::Exclusive<AncestorNode>>;
127+
pub enum AncestorList = Option<private::Exclusive<AncestorNode>>;
128128

129129
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
130130
#[inline(always)]
131-
fn access_group<U>(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U {
131+
pub fn access_group<U>(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U {
132132
unsafe { x.with(blk) }
133133
}
134134

135135
#[inline(always)]
136-
fn access_ancestors<U>(x: &private::Exclusive<AncestorNode>,
136+
pub fn access_ancestors<U>(x: &private::Exclusive<AncestorNode>,
137137
blk: fn(x: &mut AncestorNode) -> U) -> U {
138138
unsafe { x.with(blk) }
139139
}
@@ -146,9 +146,9 @@ fn access_ancestors<U>(x: &private::Exclusive<AncestorNode>,
146146
// (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list.
147147
// FIXME(#2190): Change Option<fn@(...)> to Option<fn&(...)>, to save on
148148
// allocations. Once that bug is fixed, changing the sigil should suffice.
149-
fn each_ancestor(list: &mut AncestorList,
150-
bail_opt: Option<fn@(TaskGroupInner)>,
151-
forward_blk: fn(TaskGroupInner) -> bool)
149+
pub fn each_ancestor(list: &mut AncestorList,
150+
bail_opt: Option<fn@(TaskGroupInner)>,
151+
forward_blk: fn(TaskGroupInner) -> bool)
152152
-> bool {
153153
// "Kickoff" call - there was no last generation.
154154
return !coalesce(list, bail_opt, forward_blk, uint::max_value);
@@ -271,7 +271,7 @@ fn each_ancestor(list: &mut AncestorList,
271271
}
272272

273273
// One of these per task.
274-
struct TCB {
274+
pub struct TCB {
275275
me: *rust_task,
276276
// List of tasks with whose fates this one's is intertwined.
277277
tasks: TaskGroupArc, // 'none' means the group has failed.
@@ -303,7 +303,7 @@ struct TCB {
303303
}
304304
}
305305

306-
fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList,
306+
pub fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList,
307307
is_main: bool, notifier: Option<AutoNotify>) -> TCB {
308308

309309
let notifier = move notifier;
@@ -318,7 +318,7 @@ fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList,
318318
}
319319
}
320320

321-
struct AutoNotify {
321+
pub struct AutoNotify {
322322
notify_chan: Chan<Notification>,
323323
mut failed: bool,
324324
drop {
@@ -327,15 +327,15 @@ struct AutoNotify {
327327
}
328328
}
329329

330-
fn AutoNotify(chan: Chan<Notification>) -> AutoNotify {
330+
pub fn AutoNotify(chan: Chan<Notification>) -> AutoNotify {
331331
AutoNotify {
332332
notify_chan: chan,
333333
failed: true // Un-set above when taskgroup successfully made.
334334
}
335335
}
336336

337-
fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task,
338-
is_member: bool) -> bool {
337+
pub fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task,
338+
is_member: bool) -> bool {
339339
let newstate = util::replace(state, None);
340340
// If 'None', the group was failing. Can't enlist.
341341
if newstate.is_some() {
@@ -350,7 +350,8 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task,
350350
}
351351

352352
// NB: Runs in destructor/post-exit context. Can't 'fail'.
353-
fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) {
353+
pub fn leave_taskgroup(state: TaskGroupInner, me: *rust_task,
354+
is_member: bool) {
354355
let newstate = util::replace(state, None);
355356
// If 'None', already failing and we've already gotten a kill signal.
356357
if newstate.is_some() {
@@ -362,7 +363,7 @@ fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) {
362363
}
363364

364365
// NB: Runs in destructor/post-exit context. Can't 'fail'.
365-
fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
366+
pub fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
366367
// NB: We could do the killing iteration outside of the group arc, by
367368
// having "let mut newstate" here, swapping inside, and iterating after.
368369
// But that would let other exiting tasks fall-through and exit while we
@@ -404,8 +405,8 @@ macro_rules! taskgroup_key (
404405
() => (cast::transmute((-2 as uint, 0u)))
405406
)
406407

407-
fn gen_child_taskgroup(linked: bool, supervised: bool)
408-
-> (TaskGroupArc, AncestorList, bool) {
408+
pub fn gen_child_taskgroup(linked: bool, supervised: bool)
409+
-> (TaskGroupArc, AncestorList, bool) {
409410
let spawner = rt::rust_get_task();
410411
/*######################################################################*
411412
* Step 1. Get spawner's taskgroup info.
@@ -486,7 +487,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
486487
}
487488
}
488489

489-
fn spawn_raw(opts: TaskOpts, +f: fn~()) {
490+
pub fn spawn_raw(opts: TaskOpts, +f: fn~()) {
490491
let (child_tg, ancestors, is_main) =
491492
gen_child_taskgroup(opts.linked, opts.supervised);
492493

src/test/run-pass/issue-783.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern mod std;
22
use comm::*;
3-
use task::*;
3+
use task::spawn;
44

55
fn a() {
66
fn doit() {

0 commit comments

Comments
 (0)