Skip to content

Commit d39ea47

Browse files
committed
rt: Remove rust_task_user struct
1 parent 1dad32c commit d39ea47

File tree

5 files changed

+25
-36
lines changed

5 files changed

+25
-36
lines changed

src/rt/rust_builtin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ rust_new_sched(uintptr_t threads) {
439439
extern "C" CDECL rust_task_id
440440
get_task_id() {
441441
rust_task *task = rust_task_thread::get_task();
442-
return task->user.id;
442+
return task->id;
443443
}
444444

445445
static rust_task_id

src/rt/rust_kernel.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ rust_kernel::register_task(rust_task *task) {
161161
uintptr_t new_live_tasks;
162162
{
163163
scoped_lock with(task_lock);
164-
task->user.id = max_task_id++;
165-
task_table.put(task->user.id, task);
164+
task->id = max_task_id++;
165+
task_table.put(task->id, task);
166166
new_live_tasks = ++live_tasks;
167167
}
168-
K(srv, task->user.id != INTPTR_MAX, "Hit the maximum task id");
169-
KLOG_("Registered task %" PRIdPTR, task->user.id);
168+
K(srv, task->id != INTPTR_MAX, "Hit the maximum task id");
169+
KLOG_("Registered task %" PRIdPTR, task->id);
170170
KLOG_("Total outstanding tasks: %d", new_live_tasks);
171171
}
172172

src/rt/rust_task.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
190190
rust_task *spawner, const char *name,
191191
size_t init_stack_sz) :
192192
ref_count(1),
193+
id(0),
194+
notify_enabled(false),
193195
stk(NULL),
194196
runtime_sp(0),
195197
sched(thread->sched),
@@ -216,12 +218,8 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
216218
LOGPTR(thread, "new task", (uintptr_t)this);
217219
DLOG(thread, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this);
218220

219-
assert((void*)this == (void*)&user);
220-
221-
user.notify_enabled = 0;
222-
223221
stk = new_stk(thread, this, init_stack_sz);
224-
user.rust_sp = stk->end;
222+
rust_sp = stk->end;
225223
if (supervisor) {
226224
supervisor->ref();
227225
}
@@ -338,7 +336,7 @@ rust_task::start(spawn_fn spawnee_fn,
338336

339337
I(thread, stk->data != NULL);
340338

341-
char *sp = (char *)user.rust_sp;
339+
char *sp = (char *)rust_sp;
342340

343341
sp -= sizeof(spawn_args);
344342

@@ -614,14 +612,14 @@ rust_port *rust_task::get_port_by_id(rust_port_id id) {
614612
void
615613
rust_task::notify(bool success) {
616614
// FIXME (1078) Do this in rust code
617-
if(user.notify_enabled) {
618-
rust_task *target_task = kernel->get_task_by_id(user.notify_chan.task);
615+
if(notify_enabled) {
616+
rust_task *target_task = kernel->get_task_by_id(notify_chan.task);
619617
if (target_task) {
620618
rust_port *target_port =
621-
target_task->get_port_by_id(user.notify_chan.port);
619+
target_task->get_port_by_id(notify_chan.port);
622620
if(target_port) {
623621
task_notification msg;
624-
msg.id = user.id;
622+
msg.id = id;
625623
msg.result = !success ? tr_failure : tr_success;
626624

627625
target_port->send(&msg);
@@ -715,8 +713,8 @@ rust_task::check_stack_canary() {
715713

716714
void
717715
rust_task::config_notify(chan_handle chan) {
718-
user.notify_enabled = true;
719-
user.notify_chan = chan;
716+
notify_enabled = true;
717+
notify_chan = chan;
720718
}
721719

722720
//

src/rt/rust_task.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ struct frame_glue_fns {
3131
uintptr_t reloc_glue_off;
3232
};
3333

34-
// portions of the task structure that are accessible from the standard
35-
// library. This struct must agree with the std::task::rust_task record.
36-
struct rust_task_user {
37-
rust_task_id id;
38-
intptr_t notify_enabled; // this is way more bits than necessary, but it
39-
// simplifies the alignment.
40-
chan_handle notify_chan;
41-
uintptr_t rust_sp; // Saved sp when not running.
42-
};
43-
4434
// std::lib::task::task_result
4535
typedef unsigned long task_result;
4636
#define tr_success 0
@@ -57,10 +47,14 @@ struct task_notification {
5747
struct
5848
rust_task : public kernel_owned<rust_task>, rust_cond
5949
{
60-
rust_task_user user;
61-
6250
RUST_ATOMIC_REFCOUNT();
6351

52+
rust_task_id id;
53+
bool notify_enabled;
54+
chan_handle notify_chan;
55+
56+
uintptr_t rust_sp; // Saved sp when not running.
57+
6458
context ctx;
6559
stk_seg *stk;
6660
uintptr_t runtime_sp; // Runtime sp while task running.

src/rt/rust_task_thread.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ rust_task_thread::reap_dead_tasks() {
137137
for (size_t i = 0; i < dead_tasks_len; ++i) {
138138
rust_task *task = dead_tasks_copy[i];
139139
// Release the task from the kernel so nobody else can get at it
140-
kernel->release_task_id(task->user.id);
140+
kernel->release_task_id(task->id);
141141
// Deref the task, which may cause it to request us to release it
142142
task->deref();
143143
}
@@ -151,7 +151,7 @@ rust_task_thread::release_task(rust_task *task) {
151151
// Nobody should have a ref to the task at this point
152152
I(this, task->ref_count == 0);
153153
// Kernel should not know about the task any more
154-
I(this, kernel->get_task_by_id(task->user.id) == NULL);
154+
I(this, kernel->get_task_by_id(task->id) == NULL);
155155
// Now delete the task, which will require using this thread's
156156
// memory region.
157157
delete task;
@@ -249,11 +249,9 @@ rust_task_thread::start_main_loop() {
249249

250250
DLOG(this, task,
251251
"activating task %s 0x%" PRIxPTR
252-
", sp=0x%" PRIxPTR
253252
", state: %s",
254253
scheduled_task->name,
255254
(uintptr_t)scheduled_task,
256-
scheduled_task->user.rust_sp,
257255
scheduled_task->state->name);
258256

259257
place_task_in_tls(scheduled_task);
@@ -265,11 +263,10 @@ rust_task_thread::start_main_loop() {
265263

266264
DLOG(this, task,
267265
"returned from task %s @0x%" PRIxPTR
268-
" in state '%s', sp=0x%x, worker id=%d" PRIxPTR,
266+
" in state '%s', worker id=%d" PRIxPTR,
269267
scheduled_task->name,
270268
(uintptr_t)scheduled_task,
271269
scheduled_task->state->name,
272-
scheduled_task->user.rust_sp,
273270
id);
274271

275272
reap_dead_tasks();
@@ -305,7 +302,7 @@ rust_task_thread::create_task(rust_task *spawner, const char *name,
305302
}
306303

307304
kernel->register_task(task);
308-
return task->user.id;
305+
return task->id;
309306
}
310307

311308
void rust_task_thread::run() {

0 commit comments

Comments
 (0)