Skip to content

Commit b0722c5

Browse files
committed
core:rt:: Rename LocalServices to Task
1 parent fa18a86 commit b0722c5

File tree

9 files changed

+67
-78
lines changed

9 files changed

+67
-78
lines changed

src/libcore/logging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn log_type<T>(level: u32, object: &T) {
6767

6868
fn newsched_log_str(msg: ~str) {
6969
unsafe {
70-
match rt::local_services::unsafe_try_borrow_local_services() {
70+
match rt::task::unsafe_try_borrow_local_task() {
7171
Some(local) => {
7272
// Use the available logger
7373
(*local).logger.log(Left(msg));

src/libcore/rt/mod.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,8 @@ access to the global heap. Unlike most of `rt` the global heap is
3131
truly a global resource and generally operates independently of the
3232
rest of the runtime.
3333
34-
All other runtime features are 'local', either thread-local or
35-
task-local. Those critical to the functioning of the language are
36-
defined in the module `local_services`. Local services are those which
37-
are expected to be available to Rust code generally but rely on
38-
thread- or task-local state. These currently include the local heap,
34+
All other runtime features are task-local, including the local heap,
3935
the garbage collector, local storage, logging and the stack unwinder.
40-
Local services are primarily implemented for tasks, but may also
41-
be implemented for use outside of tasks.
4236
4337
The relationship between `rt` and the rest of the core library is
4438
not entirely clear yet and some modules will be moving into or
@@ -67,7 +61,10 @@ use ptr::Ptr;
6761
/// The global (exchange) heap.
6862
pub mod global_heap;
6963

70-
/// The Scheduler and Coroutine types.
64+
/// Implementations of language-critical runtime features like @.
65+
pub mod task;
66+
67+
/// The coroutine task scheduler, built on the `io` event loop.
7168
mod sched;
7269

7370
/// Thread-local access to the current Scheduler.
@@ -77,9 +74,6 @@ pub mod local_sched;
7774
#[path = "io/mod.rs"]
7875
pub mod io;
7976

80-
/// Thread-local implementations of language-critical runtime features like @.
81-
pub mod local_services;
82-
8377
/// The EventLoop and internal synchronous I/O interface.
8478
mod rtio;
8579

src/libcore/rt/sched.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::work_queue::WorkQueue;
1616
use super::stack::{StackPool, StackSegment};
1717
use super::rtio::{EventLoop, EventLoopObject};
1818
use super::context::Context;
19-
use super::local_services::LocalServices;
19+
use super::task::Task;
2020
use cell::Cell;
2121

2222
// A more convenient name for external callers, e.g. `local_sched::take()`
@@ -350,16 +350,16 @@ pub struct Coroutine {
350350
/// the task is dead
351351
priv saved_context: Context,
352352
/// The heap, GC, unwinding, local storage, logging
353-
local_services: LocalServices
353+
task: Task
354354
}
355355

356356
pub impl Coroutine {
357357
fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
358-
Coroutine::with_local(stack_pool, LocalServices::new(), start)
358+
Coroutine::with_task(stack_pool, Task::new(), start)
359359
}
360360

361-
fn with_local(stack_pool: &mut StackPool,
362-
local_services: LocalServices,
361+
fn with_task(stack_pool: &mut StackPool,
362+
task: Task,
363363
start: ~fn()) -> Coroutine {
364364
let start = Coroutine::build_start_wrapper(start);
365365
let mut stack = stack_pool.take_segment(MIN_STACK_SIZE);
@@ -368,7 +368,7 @@ pub impl Coroutine {
368368
return Coroutine {
369369
current_stack_segment: stack,
370370
saved_context: initial_context,
371-
local_services: local_services
371+
task: task
372372
};
373373
}
374374

@@ -385,7 +385,7 @@ pub impl Coroutine {
385385
let sched = local_sched::unsafe_borrow();
386386
let task = (*sched).current_task.get_mut_ref();
387387
// FIXME #6141: shouldn't neet to put `start()` in another closure
388-
task.local_services.run(||start());
388+
task.task.run(||start());
389389
}
390390

391391
let sched = local_sched::take();

src/libcore/rt/local_services.rs renamed to src/libcore/rt/task.rs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@
1313
//! local storage, and logging. Even a 'freestanding' Rust would likely want
1414
//! to implement this.
1515
16-
//! Local services may exist in at least three different contexts:
17-
//! when running as a task, when running in the scheduler's context,
18-
//! or when running outside of a scheduler but with local services
19-
//! (freestanding rust with local services?).
20-
2116
use prelude::*;
2217
use libc::{c_void, uintptr_t};
2318
use cast::transmute;
2419
use super::sched::local_sched;
2520
use super::local_heap::LocalHeap;
2621
use rt::logging::StdErrLogger;
2722

28-
pub struct LocalServices {
23+
pub struct Task {
2924
heap: LocalHeap,
3025
gc: GarbageCollector,
3126
storage: LocalStorage,
@@ -41,9 +36,9 @@ pub struct Unwinder {
4136
unwinding: bool,
4237
}
4338

44-
impl LocalServices {
45-
pub fn new() -> LocalServices {
46-
LocalServices {
39+
impl Task {
40+
pub fn new() -> Task {
41+
Task {
4742
heap: LocalHeap::new(),
4843
gc: GarbageCollector,
4944
storage: LocalStorage(ptr::null(), None),
@@ -53,8 +48,8 @@ impl LocalServices {
5348
}
5449
}
5550

56-
pub fn without_unwinding() -> LocalServices {
57-
LocalServices {
51+
pub fn without_unwinding() -> Task {
52+
Task {
5853
heap: LocalHeap::new(),
5954
gc: GarbageCollector,
6055
storage: LocalStorage(ptr::null(), None),
@@ -66,9 +61,9 @@ impl LocalServices {
6661

6762
pub fn run(&mut self, f: &fn()) {
6863
// This is just an assertion that `run` was called unsafely
69-
// and this instance of LocalServices is still accessible.
70-
do borrow_local_services |sched| {
71-
assert!(ptr::ref_eq(sched, self));
64+
// and this instance of Task is still accessible.
65+
do borrow_local_task |task| {
66+
assert!(ptr::ref_eq(task, self));
7267
}
7368

7469
match self.unwinder {
@@ -86,14 +81,14 @@ impl LocalServices {
8681

8782
/// Must be called manually before finalization to clean up
8883
/// thread-local resources. Some of the routines here expect
89-
/// LocalServices to be available recursively so this must be
90-
/// called unsafely, without removing LocalServices from
84+
/// Task to be available recursively so this must be
85+
/// called unsafely, without removing Task from
9186
/// thread-local-storage.
9287
fn destroy(&mut self) {
9388
// This is just an assertion that `destroy` was called unsafely
94-
// and this instance of LocalServices is still accessible.
95-
do borrow_local_services |sched| {
96-
assert!(ptr::ref_eq(sched, self));
89+
// and this instance of Task is still accessible.
90+
do borrow_local_task |task| {
91+
assert!(ptr::ref_eq(task, self));
9792
}
9893
match self.storage {
9994
LocalStorage(ptr, Some(ref dtor)) => {
@@ -105,7 +100,7 @@ impl LocalServices {
105100
}
106101
}
107102

108-
impl Drop for LocalServices {
103+
impl Drop for Task {
109104
fn finalize(&self) { assert!(self.destroyed) }
110105
}
111106

@@ -156,11 +151,11 @@ impl Unwinder {
156151

157152
/// Borrow a pointer to the installed local services.
158153
/// Fails (likely aborting the process) if local services are not available.
159-
pub fn borrow_local_services(f: &fn(&mut LocalServices)) {
154+
pub fn borrow_local_task(f: &fn(&mut Task)) {
160155
do local_sched::borrow |sched| {
161156
match sched.current_task {
162157
Some(~ref mut task) => {
163-
f(&mut task.local_services)
158+
f(&mut task.task)
164159
}
165160
None => {
166161
fail!("no local services for schedulers yet")
@@ -169,10 +164,10 @@ pub fn borrow_local_services(f: &fn(&mut LocalServices)) {
169164
}
170165
}
171166

172-
pub unsafe fn unsafe_borrow_local_services() -> *mut LocalServices {
167+
pub unsafe fn unsafe_borrow_local_task() -> *mut Task {
173168
match (*local_sched::unsafe_borrow()).current_task {
174169
Some(~ref mut task) => {
175-
let s: *mut LocalServices = &mut task.local_services;
170+
let s: *mut Task = &mut task.task;
176171
return s;
177172
}
178173
None => {
@@ -182,9 +177,9 @@ pub unsafe fn unsafe_borrow_local_services() -> *mut LocalServices {
182177
}
183178
}
184179

185-
pub unsafe fn unsafe_try_borrow_local_services() -> Option<*mut LocalServices> {
180+
pub unsafe fn unsafe_try_borrow_local_task() -> Option<*mut Task> {
186181
if local_sched::exists() {
187-
Some(unsafe_borrow_local_services())
182+
Some(unsafe_borrow_local_task())
188183
} else {
189184
None
190185
}

src/libcore/rt/test.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use option::*;
1313
use cell::Cell;
1414
use result::{Result, Ok, Err};
1515
use super::io::net::ip::{IpAddr, Ipv4};
16-
use rt::local_services::LocalServices;
16+
use rt::task::Task;
1717
use rt::thread::Thread;
1818

1919
/// Creates a new scheduler in a new thread and runs a task in it,
@@ -28,9 +28,9 @@ pub fn run_in_newsched_task(f: ~fn()) {
2828

2929
do run_in_bare_thread {
3030
let mut sched = ~UvEventLoop::new_scheduler();
31-
let task = ~Coroutine::with_local(&mut sched.stack_pool,
32-
LocalServices::without_unwinding(),
33-
f.take());
31+
let task = ~Coroutine::with_task(&mut sched.stack_pool,
32+
Task::without_unwinding(),
33+
f.take());
3434
sched.enqueue_task(task);
3535
sched.run();
3636
}
@@ -41,9 +41,9 @@ pub fn spawntask(f: ~fn()) {
4141
use super::sched::*;
4242

4343
let mut sched = local_sched::take();
44-
let task = ~Coroutine::with_local(&mut sched.stack_pool,
45-
LocalServices::without_unwinding(),
46-
f);
44+
let task = ~Coroutine::with_task(&mut sched.stack_pool,
45+
Task::without_unwinding(),
46+
f);
4747
do sched.switch_running_tasks_and_then(task) |task| {
4848
let task = Cell(task);
4949
let sched = local_sched::take();
@@ -56,9 +56,9 @@ pub fn spawntask_immediately(f: ~fn()) {
5656
use super::sched::*;
5757

5858
let mut sched = local_sched::take();
59-
let task = ~Coroutine::with_local(&mut sched.stack_pool,
60-
LocalServices::without_unwinding(),
61-
f);
59+
let task = ~Coroutine::with_task(&mut sched.stack_pool,
60+
Task::without_unwinding(),
61+
f);
6262
do sched.switch_running_tasks_and_then(task) |task| {
6363
let task = Cell(task);
6464
do local_sched::borrow |sched| {
@@ -72,9 +72,9 @@ pub fn spawntask_later(f: ~fn()) {
7272
use super::sched::*;
7373

7474
let mut sched = local_sched::take();
75-
let task = ~Coroutine::with_local(&mut sched.stack_pool,
76-
LocalServices::without_unwinding(),
77-
f);
75+
let task = ~Coroutine::with_task(&mut sched.stack_pool,
76+
Task::without_unwinding(),
77+
f);
7878

7979
sched.enqueue_task(task);
8080
local_sched::put(sched);
@@ -89,9 +89,9 @@ pub fn spawntask_random(f: ~fn()) {
8989
let run_now: bool = Rand::rand(&mut rng);
9090

9191
let mut sched = local_sched::take();
92-
let task = ~Coroutine::with_local(&mut sched.stack_pool,
93-
LocalServices::without_unwinding(),
94-
f);
92+
let task = ~Coroutine::with_task(&mut sched.stack_pool,
93+
Task::without_unwinding(),
94+
f);
9595

9696
if run_now {
9797
do sched.switch_running_tasks_and_then(task) |task| {
@@ -155,9 +155,9 @@ pub fn spawntask_thread(f: ~fn()) -> Thread {
155155
let f = Cell(f);
156156
let thread = do Thread::start {
157157
let mut sched = ~UvEventLoop::new_scheduler();
158-
let task = ~Coroutine::with_local(&mut sched.stack_pool,
159-
LocalServices::without_unwinding(),
160-
f.take());
158+
let task = ~Coroutine::with_task(&mut sched.stack_pool,
159+
Task::without_unwinding(),
160+
f.take());
161161
sched.enqueue_task(task);
162162
sched.run();
163163
};

src/libcore/sys.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl FailWithCause for &'static str {
204204
pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
205205
use option::Option;
206206
use rt::{context, OldTaskContext, TaskContext};
207-
use rt::local_services::{unsafe_borrow_local_services, Unwinder};
207+
use rt::task::{unsafe_borrow_local_task, Unwinder};
208208

209209
let context = context();
210210
match context {
@@ -233,8 +233,8 @@ pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
233233

234234
gc::cleanup_stack_for_failure();
235235

236-
let local_services = unsafe_borrow_local_services();
237-
let unwinder: &mut Option<Unwinder> = &mut (*local_services).unwinder;
236+
let task = unsafe_borrow_local_task();
237+
let unwinder: &mut Option<Unwinder> = &mut (*task).unwinder;
238238
match *unwinder {
239239
Some(ref mut unwinder) => unwinder.begin_unwind(),
240240
None => abort!("failure without unwinder. aborting process")

src/libcore/task/local_data_priv.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use task::rt;
1818
use local_data::LocalDataKey;
1919

2020
use super::rt::rust_task;
21-
use rt::local_services::LocalStorage;
21+
use rt::task::LocalStorage;
2222

2323
pub enum Handle {
2424
OldHandle(*rust_task),
@@ -28,15 +28,15 @@ pub enum Handle {
2828
impl Handle {
2929
pub fn new() -> Handle {
3030
use rt::{context, OldTaskContext};
31-
use rt::local_services::unsafe_borrow_local_services;
31+
use rt::task::unsafe_borrow_local_task;
3232
unsafe {
3333
match context() {
3434
OldTaskContext => {
3535
OldHandle(rt::rust_get_task())
3636
}
3737
_ => {
38-
let local_services = unsafe_borrow_local_services();
39-
NewHandle(&mut (*local_services).storage)
38+
let task = unsafe_borrow_local_task();
39+
NewHandle(&mut (*task).storage)
4040
}
4141
}
4242
}

src/libcore/task/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ pub fn failing() -> bool {
504504
//! True if the running task has failed
505505
506506
use rt::{context, OldTaskContext};
507-
use rt::local_services::borrow_local_services;
507+
use rt::task::borrow_local_task;
508508

509509
match context() {
510510
OldTaskContext => {
@@ -514,7 +514,7 @@ pub fn failing() -> bool {
514514
}
515515
_ => {
516516
let mut unwinding = false;
517-
do borrow_local_services |local| {
517+
do borrow_local_task |local| {
518518
unwinding = match local.unwinder {
519519
Some(unwinder) => {
520520
unwinder.unwinding

0 commit comments

Comments
 (0)