rt: Call maybe_gc on mallocs
This commit is contained in:
parent
390dd38619
commit
cede5e53b3
@ -3,6 +3,7 @@
|
||||
#include <utility>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "rust_gc.h"
|
||||
#include "rust_internal.h"
|
||||
|
||||
#ifdef __WIN32__
|
||||
@ -31,38 +32,51 @@ class safe_point_map {
|
||||
|
||||
public:
|
||||
safe_point_map() {
|
||||
const uintptr_t *data;
|
||||
#ifdef __WIN32__
|
||||
data = (const uintptr_t *)GetProcAddress(GetModuleHandle(NULL),
|
||||
"rust_gc_safe_points");
|
||||
#else
|
||||
data = (const uintptr_t *)dlsym(RTLD_DEFAULT, "rust_gc_safe_points");
|
||||
#endif
|
||||
const uintptr_t *data = get_safe_point_data();
|
||||
n_safe_points = *data++;
|
||||
index = (const std::pair<void *,const safe_point *> *)data;
|
||||
data += n_safe_points * 2;
|
||||
safe_points = (const safe_point *)data;
|
||||
}
|
||||
|
||||
static const uintptr_t *get_safe_point_data() {
|
||||
static bool init = false;
|
||||
static const uintptr_t *data;
|
||||
if (!init) {
|
||||
#ifdef __WIN32__
|
||||
data = (const uintptr_t *)GetProcAddress(GetModuleHandle(NULL),
|
||||
"rust_gc_safe_points");
|
||||
#else
|
||||
data = (const uintptr_t *)dlsym(RTLD_DEFAULT,
|
||||
"rust_gc_safe_points");
|
||||
#endif
|
||||
init = true;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
gc() {
|
||||
gc(rust_task *task) {
|
||||
safe_point_map map;
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
void
|
||||
maybe_gc() {
|
||||
maybe_gc(rust_task *task) {
|
||||
if (safe_point_map::get_safe_point_data() == NULL)
|
||||
return;
|
||||
|
||||
// FIXME: We ought to lock this.
|
||||
static int zeal = -1;
|
||||
if (zeal == -1) {
|
||||
char *ev = getenv("RUST_GC_ZEAL");
|
||||
zeal = ev[0] != '\0' && ev[0] != '0';
|
||||
zeal = ev && ev[0] != '\0' && ev[0] != '0';
|
||||
}
|
||||
|
||||
if (zeal)
|
||||
gc();
|
||||
gc(task);
|
||||
}
|
||||
|
||||
}
|
||||
|
10
src/rt/rust_gc.h
Normal file
10
src/rt/rust_gc.h
Normal file
@ -0,0 +1,10 @@
|
||||
// Rust garbage collection.
|
||||
|
||||
struct rust_task;
|
||||
|
||||
namespace gc {
|
||||
|
||||
void maybe_gc(rust_task *task);
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "rust_gc.h"
|
||||
#include "rust_internal.h"
|
||||
#include "rust_upcall.h"
|
||||
|
||||
@ -130,6 +131,8 @@ upcall_malloc(rust_task *task, size_t nbytes, type_desc *td) {
|
||||
" with gc-chain head = 0x%" PRIxPTR,
|
||||
nbytes, td, task->gc_alloc_chain);
|
||||
|
||||
gc::maybe_gc(task);
|
||||
|
||||
// TODO: Maybe use dladdr here to find a more useful name for the
|
||||
// type_desc.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user