Skip to content

Commit c1960e4

Browse files
committed
---
yaml --- r: 660 b: refs/heads/master c: a493350 h: refs/heads/master v: v3
1 parent ce851ec commit c1960e4

23 files changed

+280
-130
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: f985fded3ede8a7677ca6c9c77817d27bc9ae492
2+
refs/heads/master: a493350eb5ab38ba8a6563f3eb4a090d257b0d3a

trunk/src/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ RUNTIME_CS := rt/sync/timer.cpp \
257257
rt/rust_comm.cpp \
258258
rt/rust_dom.cpp \
259259
rt/rust_task.cpp \
260+
rt/rust_task_list.cpp \
260261
rt/rust_proxy.cpp \
261262
rt/rust_chan.cpp \
262263
rt/rust_port.cpp \
@@ -270,6 +271,7 @@ RUNTIME_CS := rt/sync/timer.cpp \
270271
rt/rust_kernel.cpp \
271272
rt/memory_region.cpp \
272273
rt/test/rust_test_harness.cpp \
274+
rt/test/rust_test_runtime.cpp \
273275
rt/test/rust_test_util.cpp
274276

275277
RUNTIME_HDR := rt/globals.h \
@@ -281,6 +283,7 @@ RUNTIME_HDR := rt/globals.h \
281283
rt/rust_port.h \
282284
rt/rust_dom.h \
283285
rt/rust_task.h \
286+
rt/rust_task_list.h \
284287
rt/rust_proxy.h \
285288
rt/rust_log.h \
286289
rt/rust_message.h \
@@ -297,6 +300,7 @@ RUNTIME_HDR := rt/globals.h \
297300
rt/memory_region.h \
298301
rt/memory.h \
299302
rt/test/rust_test_harness.h \
303+
rt/test/rust_test_runtime.h \
300304
rt/test/rust_test_util.h
301305

302306
RUNTIME_INCS := -Irt/isaac -Irt/uthash

trunk/src/rt/rust_dom.cpp

Lines changed: 28 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#include <stdarg.h>
33
#include "rust_internal.h"
44

5-
template class ptr_vec<rust_task>;
6-
75
rust_dom::rust_dom(rust_kernel *kernel,
86
rust_message_queue *message_queue, rust_srv *srv,
97
rust_crate const *root_crate, const char *name) :
@@ -14,9 +12,10 @@ rust_dom::rust_dom(rust_kernel *kernel,
1412
local_region(&srv->local_region),
1513
synchronized_region(&srv->synchronized_region),
1614
name(name),
17-
running_tasks(this),
18-
blocked_tasks(this),
19-
dead_tasks(this),
15+
newborn_tasks(this, "newborn"),
16+
running_tasks(this, "running"),
17+
blocked_tasks(this, "blocked"),
18+
dead_tasks(this, "dead"),
2019
caches(this),
2120
root_task(NULL),
2221
curr_task(NULL),
@@ -31,28 +30,16 @@ rust_dom::rust_dom(rust_kernel *kernel,
3130
pthread_attr_setstacksize(&attr, 1024 * 1024);
3231
pthread_attr_setdetachstate(&attr, true);
3332
#endif
34-
root_task = new (this) rust_task(this, NULL, name);
35-
}
36-
37-
static void
38-
del_all_tasks(rust_dom *dom, ptr_vec<rust_task> *v) {
39-
I(dom, v);
40-
while (v->length()) {
41-
dom->log(rust_log::TASK, "deleting task 0x%" PRIdPTR,
42-
v->length() - 1);
43-
delete v->pop();
44-
}
33+
root_task = create_task(NULL, name);
4534
}
4635

4736
rust_dom::~rust_dom() {
4837
log(rust_log::MEM | rust_log::DOM,
4938
"~rust_dom %s @0x%" PRIxPTR, name, (uintptr_t)this);
50-
log(rust_log::TASK, "deleting all running tasks");
51-
del_all_tasks(this, &running_tasks);
52-
log(rust_log::TASK, "deleting all blocked tasks");
53-
del_all_tasks(this, &blocked_tasks);
54-
log(rust_log::TASK, "deleting all dead tasks");
55-
del_all_tasks(this, &dead_tasks);
39+
newborn_tasks.delete_all();
40+
running_tasks.delete_all();
41+
blocked_tasks.delete_all();
42+
dead_tasks.delete_all();
5643
#ifndef __WIN32__
5744
pthread_attr_destroy(&attr);
5845
#endif
@@ -198,42 +185,10 @@ rust_dom::win32_require(LPCTSTR fn, BOOL ok) {
198185
#endif
199186

200187
size_t
201-
rust_dom::n_live_tasks()
202-
{
188+
rust_dom::number_of_live_tasks() {
203189
return running_tasks.length() + blocked_tasks.length();
204190
}
205191

206-
void
207-
rust_dom::add_task_to_state_vec(ptr_vec<rust_task> *v, rust_task *task)
208-
{
209-
log(rust_log::MEM|rust_log::TASK,
210-
"adding task %s @0x%" PRIxPTR " in state '%s' to vec 0x%" PRIxPTR,
211-
task->name, (uintptr_t)task, state_vec_name(v), (uintptr_t)v);
212-
v->push(task);
213-
}
214-
215-
216-
void
217-
rust_dom::remove_task_from_state_vec(ptr_vec<rust_task> *v, rust_task *task)
218-
{
219-
log(rust_log::MEM|rust_log::TASK,
220-
"removing task %s @0x%" PRIxPTR " in state '%s' from vec 0x%" PRIxPTR,
221-
task->name, (uintptr_t)task, state_vec_name(v), (uintptr_t)v);
222-
I(this, (*v)[task->idx] == task);
223-
v->swap_delete(task);
224-
}
225-
226-
const char *
227-
rust_dom::state_vec_name(ptr_vec<rust_task> *v)
228-
{
229-
if (v == &running_tasks)
230-
return "running";
231-
if (v == &blocked_tasks)
232-
return "blocked";
233-
I(this, v == &dead_tasks);
234-
return "dead";
235-
}
236-
237192
/**
238193
* Delete any dead tasks.
239194
*/
@@ -243,7 +198,7 @@ rust_dom::reap_dead_tasks() {
243198
rust_task *task = dead_tasks[i];
244199
if (task->ref_count == 0) {
245200
I(this, task->tasks_waiting_to_join.is_empty());
246-
dead_tasks.swap_delete(task);
201+
dead_tasks.remove(task);
247202
log(rust_log::TASK,
248203
"deleting unreferenced dead task %s @0x%" PRIxPTR,
249204
task->name, task);
@@ -288,7 +243,6 @@ rust_dom::schedule_task() {
288243
return (rust_task *)running_tasks[i];
289244
}
290245
}
291-
// log(rust_log::DOM|rust_log::TASK, "no schedulable tasks");
292246
return NULL;
293247
}
294248

@@ -334,16 +288,16 @@ rust_dom::log_state() {
334288
* drop to zero.
335289
*/
336290
int
337-
rust_dom::start_main_loop()
338-
{
291+
rust_dom::start_main_loop() {
339292
// Make sure someone is watching, to pull us out of infinite loops.
340293
rust_timer timer(this);
341294

342-
log(rust_log::DOM, "running main-loop on domain %s @0x%" PRIxPTR,
343-
name, this);
344-
logptr("exit-task glue", root_crate->get_exit_task_glue());
295+
log(rust_log::DOM, "started domain loop");
296+
log(rust_log::DOM | rust_log::MEM,
297+
"activate glue: " PTR ", exit glue: " PTR,
298+
root_crate->get_activate_glue(), root_crate->get_exit_task_glue());
345299

346-
while (n_live_tasks() > 0) {
300+
while (number_of_live_tasks() > 0) {
347301
A(this, kernel->is_deadlocked() == false, "deadlock");
348302

349303
drain_incoming_message_queue(true);
@@ -377,7 +331,7 @@ rust_dom::start_main_loop()
377331
(uintptr_t)scheduled_task,
378332
scheduled_task->rust_sp,
379333
scheduled_task->ref_count,
380-
scheduled_task->state_str());
334+
scheduled_task->state->name);
381335

382336
interrupt_flag = 0;
383337

@@ -388,7 +342,7 @@ rust_dom::start_main_loop()
388342
" in state '%s', sp=0x%" PRIxPTR,
389343
scheduled_task->name,
390344
(uintptr_t)scheduled_task,
391-
state_vec_name(scheduled_task->state),
345+
scheduled_task->state->name,
392346
scheduled_task->rust_sp);
393347

394348
I(this, scheduled_task->rust_sp >=
@@ -443,6 +397,15 @@ rust_dom::get_cache(rust_crate const *crate) {
443397
return cache;
444398
}
445399

400+
rust_task *
401+
rust_dom::create_task(rust_task *spawner, const char *name) {
402+
rust_task *task =
403+
new (this) rust_task (this, &newborn_tasks, spawner, name);
404+
log(rust_log::TASK, "created task: " PTR ", spawner: %s, name: %s",
405+
task, spawner ? spawner->name : "null", name);
406+
newborn_tasks.append(task);
407+
return task;
408+
}
446409

447410
//
448411
// Local Variables:

trunk/src/rt/rust_dom.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ struct rust_dom : public kernel_owned<rust_dom>, rc_base<rust_dom>
1818
memory_region local_region;
1919
memory_region synchronized_region;
2020
const char *const name;
21-
ptr_vec<rust_task> running_tasks;
22-
ptr_vec<rust_task> blocked_tasks;
23-
ptr_vec<rust_task> dead_tasks;
21+
22+
rust_task_list newborn_tasks;
23+
rust_task_list running_tasks;
24+
rust_task_list blocked_tasks;
25+
rust_task_list dead_tasks;
26+
2427
ptr_vec<rust_crate_cache> caches;
28+
2529
randctx rctx;
2630
rust_task *root_task;
2731
rust_task *curr_task;
@@ -71,10 +75,7 @@ struct rust_dom : public kernel_owned<rust_dom>, rc_base<rust_dom>
7175
#endif
7276

7377
rust_crate_cache *get_cache(rust_crate const *crate);
74-
size_t n_live_tasks();
75-
void add_task_to_state_vec(ptr_vec<rust_task> *v, rust_task *task);
76-
void remove_task_from_state_vec(ptr_vec<rust_task> *v, rust_task *task);
77-
const char *state_vec_name(ptr_vec<rust_task> *v);
78+
size_t number_of_live_tasks();
7879

7980
void reap_dead_tasks();
8081
rust_task *schedule_task();
@@ -83,6 +84,8 @@ struct rust_dom : public kernel_owned<rust_dom>, rc_base<rust_dom>
8384

8485
void log_state();
8586
static void log_all_state();
87+
88+
rust_task *create_task(rust_task *spawner, const char *name);
8689
};
8790

8891
//

trunk/src/rt/rust_internal.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ template <typename T> struct region_owned {
124124
}
125125
};
126126

127+
#include "rust_task_list.h"
128+
127129
// A cond(ition) is something we can block on. This can be a channel
128130
// (writing), a port (reading) or a task (waiting).
129131

@@ -203,9 +205,7 @@ crate_rel(rust_crate const *crate, T const *t) {
203205

204206
typedef void CDECL (*activate_glue_ty)(rust_task *);
205207

206-
class
207-
rust_crate
208-
{
208+
class rust_crate {
209209
// The following fields are emitted by the compiler for the static
210210
// rust_crate object inside each compiled crate.
211211

@@ -563,6 +563,7 @@ struct gc_alloc {
563563

564564
#include "test/rust_test_harness.h"
565565
#include "test/rust_test_util.h"
566+
#include "test/rust_test_runtime.h"
566567

567568
//
568569
// Local Variables:

trunk/src/rt/rust_kernel.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ rust_kernel::rust_kernel(rust_srv *srv) :
44
_region(&srv->local_region),
55
_log(srv, NULL),
66
_srv(srv),
7-
_interrupt_kernel_loop(FALSE),
8-
domains(&srv->local_region),
9-
message_queues(&srv->local_region) {
7+
_interrupt_kernel_loop(FALSE) {
108
// Nop.
119
}
1210

@@ -22,6 +20,9 @@ rust_kernel::create_domain(const rust_crate *crate, const char *name) {
2220
message_queue->associate(handle);
2321
domains.append(dom);
2422
message_queues.append(message_queue);
23+
log(rust_log::KERN | rust_log::TASK,
24+
"created domain: " PTR ", name: %s, index: %d, domains %d",
25+
dom, name, dom->list_index, domains.length());
2526
_kernel_lock.signal_all();
2627
_kernel_lock.unlock();
2728
return handle;
@@ -30,8 +31,9 @@ rust_kernel::create_domain(const rust_crate *crate, const char *name) {
3031
void
3132
rust_kernel::destroy_domain(rust_dom *dom) {
3233
_kernel_lock.lock();
33-
log(rust_log::KERN, "deleting domain: " PTR ", index: %d, domains %d",
34-
dom, dom->list_index, domains.length());
34+
log(rust_log::KERN,
35+
"deleting domain: " PTR ", name: %s, index: %d, domains %d",
36+
dom, dom->name, dom->list_index, domains.length());
3537
domains.remove(dom);
3638
dom->message_queue->disassociate();
3739
rust_srv *srv = dom->srv;

0 commit comments

Comments
 (0)