Skip to content

Commit b5faacb

Browse files
committed
---
yaml --- r: 4849 b: refs/heads/master c: cede5e5 h: refs/heads/master i: 4847: 829afde v: v3
1 parent e7eb847 commit b5faacb

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
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: 390dd3861933db71339dba01f09a83594a85d3eb
2+
refs/heads/master: cede5e53b3af92c12ae7ba6591fce7f8ca81979f

trunk/src/rt/rust_gc.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <utility>
44
#include <stdint.h>
55

6+
#include "rust_gc.h"
67
#include "rust_internal.h"
78

89
#ifdef __WIN32__
@@ -31,38 +32,51 @@ class safe_point_map {
3132

3233
public:
3334
safe_point_map() {
34-
const uintptr_t *data;
35-
#ifdef __WIN32__
36-
data = (const uintptr_t *)GetProcAddress(GetModuleHandle(NULL),
37-
"rust_gc_safe_points");
38-
#else
39-
data = (const uintptr_t *)dlsym(RTLD_DEFAULT, "rust_gc_safe_points");
40-
#endif
35+
const uintptr_t *data = get_safe_point_data();
4136
n_safe_points = *data++;
4237
index = (const std::pair<void *,const safe_point *> *)data;
4338
data += n_safe_points * 2;
4439
safe_points = (const safe_point *)data;
4540
}
41+
42+
static const uintptr_t *get_safe_point_data() {
43+
static bool init = false;
44+
static const uintptr_t *data;
45+
if (!init) {
46+
#ifdef __WIN32__
47+
data = (const uintptr_t *)GetProcAddress(GetModuleHandle(NULL),
48+
"rust_gc_safe_points");
49+
#else
50+
data = (const uintptr_t *)dlsym(RTLD_DEFAULT,
51+
"rust_gc_safe_points");
52+
#endif
53+
init = true;
54+
}
55+
return data;
56+
}
4657
};
4758

4859
void
49-
gc() {
60+
gc(rust_task *task) {
5061
safe_point_map map;
5162

5263
// TODO
5364
}
5465

5566
void
56-
maybe_gc() {
67+
maybe_gc(rust_task *task) {
68+
if (safe_point_map::get_safe_point_data() == NULL)
69+
return;
70+
5771
// FIXME: We ought to lock this.
5872
static int zeal = -1;
5973
if (zeal == -1) {
6074
char *ev = getenv("RUST_GC_ZEAL");
61-
zeal = ev[0] != '\0' && ev[0] != '0';
75+
zeal = ev && ev[0] != '\0' && ev[0] != '0';
6276
}
6377

6478
if (zeal)
65-
gc();
79+
gc(task);
6680
}
6781

6882
}

trunk/src/rt/rust_gc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Rust garbage collection.
2+
3+
struct rust_task;
4+
5+
namespace gc {
6+
7+
void maybe_gc(rust_task *task);
8+
9+
}
10+

trunk/src/rt/rust_upcall.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "rust_gc.h"
12
#include "rust_internal.h"
23
#include "rust_upcall.h"
34

@@ -130,6 +131,8 @@ upcall_malloc(rust_task *task, size_t nbytes, type_desc *td) {
130131
" with gc-chain head = 0x%" PRIxPTR,
131132
nbytes, td, task->gc_alloc_chain);
132133

134+
gc::maybe_gc(task);
135+
133136
// TODO: Maybe use dladdr here to find a more useful name for the
134137
// type_desc.
135138

0 commit comments

Comments
 (0)