Skip to content

Commit 9e422b3

Browse files
committed
---
yaml --- r: 12244 b: refs/heads/master c: 218dd08 h: refs/heads/master v: v3
1 parent 4063b3d commit 9e422b3

File tree

7 files changed

+58
-8
lines changed

7 files changed

+58
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 771c1be6a64225d416ad99a860f1c8d34ce3a18b
2+
refs/heads/master: 218dd084697ed2ce58812ef9e69cdc86cb83bcf2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/mk/rt.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ RUNTIME_CS_$(1) := \
5353
rt/rust_sched_loop.cpp \
5454
rt/rust_sched_launcher.cpp \
5555
rt/rust_scheduler.cpp \
56+
rt/rust_sched_reaper.cpp \
5657
rt/rust_task.cpp \
5758
rt/rust_stack.cpp \
5859
rt/rust_port.cpp \

trunk/src/rt/rust.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
9393
root_task->start((spawn_fn)main_fn, NULL, args->args);
9494
root_task = NULL;
9595

96-
int ret = kernel->wait_for_schedulers();
96+
int ret = kernel->wait_for_exit();
9797
delete args;
9898
delete kernel;
9999
delete srv;

trunk/src/rt/rust_kernel.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rust_kernel::rust_kernel(rust_srv *srv) :
1717
max_port_id(0),
1818
rval(0),
1919
max_sched_id(0),
20+
sched_reaper(this),
2021
env(srv->env)
2122
{
2223
}
@@ -62,13 +63,19 @@ rust_kernel::create_scheduler(size_t num_threads) {
6263
rust_scheduler *sched;
6364
{
6465
scoped_lock with(sched_lock);
66+
// If this is the first scheduler then we need to launch
67+
// the scheduler reaper.
68+
bool start_reaper = sched_table.empty();
6569
id = max_sched_id++;
6670
K(srv, id != INTPTR_MAX, "Hit the maximum scheduler id");
6771
sched = new (this, "rust_scheduler")
6872
rust_scheduler(this, srv, num_threads, id);
6973
bool is_new = sched_table
7074
.insert(std::pair<rust_sched_id, rust_scheduler*>(id, sched)).second;
7175
A(this, is_new, "Reusing a sched id?");
76+
if (start_reaper) {
77+
sched_reaper.start();
78+
}
7279
}
7380
sched->start_task_threads();
7481
return id;
@@ -96,12 +103,12 @@ rust_kernel::release_scheduler_id(rust_sched_id id) {
96103
}
97104

98105
/*
99-
Called on the main thread to wait for the kernel to exit. This function is
100-
also used to join on every terminating scheduler thread, so that we can be
101-
sure they have completely exited before the process exits. If we don't join
102-
them then we can see valgrind errors due to un-freed pthread memory.
106+
Called by rust_sched_reaper to join every every terminating scheduler thread,
107+
so that we can be sure they have completely exited before the process exits.
108+
If we don't join them then we can see valgrind errors due to un-freed pthread
109+
memory.
103110
*/
104-
int
111+
void
105112
rust_kernel::wait_for_schedulers()
106113
{
107114
scoped_lock with(sched_lock);
@@ -120,6 +127,12 @@ rust_kernel::wait_for_schedulers()
120127
sched_lock.wait();
121128
}
122129
}
130+
}
131+
132+
/* Called on the main thread to wait for the kernel to exit */
133+
int
134+
rust_kernel::wait_for_exit() {
135+
sched_reaper.join();
123136
return rval;
124137
}
125138

trunk/src/rt/rust_kernel.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <vector>
77
#include "memory_region.h"
88
#include "rust_log.h"
9+
#include "rust_sched_reaper.h"
910

1011
struct rust_task_thread;
1112
class rust_scheduler;
@@ -46,6 +47,8 @@ class rust_kernel {
4647
// A list of scheduler ids that are ready to exit
4748
std::vector<rust_sched_id> join_list;
4849

50+
rust_sched_reaper sched_reaper;
51+
4952
public:
5053

5154
struct rust_env *env;
@@ -66,7 +69,8 @@ class rust_kernel {
6669
rust_scheduler* get_scheduler_by_id(rust_sched_id id);
6770
// Called by a scheduler to indicate that it is terminating
6871
void release_scheduler_id(rust_sched_id id);
69-
int wait_for_schedulers();
72+
void wait_for_schedulers();
73+
int wait_for_exit();
7074

7175
#ifdef __WIN32__
7276
void win32_require(LPCTSTR fn, BOOL ok);

trunk/src/rt/rust_sched_reaper.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "rust_internal.h"
2+
#include "rust_kernel.h"
3+
#include "rust_sched_reaper.h"
4+
5+
// NB: We're using a very small stack here
6+
const size_t STACK_SIZE = 1024*20;
7+
8+
rust_sched_reaper::rust_sched_reaper(rust_kernel *kernel)
9+
: rust_thread(STACK_SIZE), kernel(kernel) {
10+
}
11+
12+
void
13+
rust_sched_reaper::run() {
14+
kernel->wait_for_schedulers();
15+
}

trunk/src/rt/rust_sched_reaper.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef RUST_SCHED_REAPER_H
2+
#define RUST_SCHED_REAPER_H
3+
4+
#include "sync/rust_thread.h"
5+
6+
class rust_kernel;
7+
8+
/* Responsible for joining with rust_schedulers */
9+
class rust_sched_reaper : public rust_thread {
10+
private:
11+
rust_kernel *kernel;
12+
public:
13+
rust_sched_reaper(rust_kernel *kernel);
14+
virtual void run();
15+
};
16+
17+
#endif /* RUST_SCHED_REAPER_H */

0 commit comments

Comments
 (0)