about summary refs log tree commit diff
path: root/src/rt/rust_gc.cpp
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-08-19 13:03:46 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-08-19 14:30:01 -0700
commitcede5e53b3af92c12ae7ba6591fce7f8ca81979f (patch)
tree441629abbc494baac5e9364af96cc949009820dd /src/rt/rust_gc.cpp
parent390dd3861933db71339dba01f09a83594a85d3eb (diff)
downloadrust-cede5e53b3af92c12ae7ba6591fce7f8ca81979f.tar.gz
rust-cede5e53b3af92c12ae7ba6591fce7f8ca81979f.zip
rt: Call maybe_gc on mallocs
Diffstat (limited to 'src/rt/rust_gc.cpp')
-rw-r--r--src/rt/rust_gc.cpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/rt/rust_gc.cpp b/src/rt/rust_gc.cpp
index 257df4c8134..9b8743dd03e 100644
--- a/src/rt/rust_gc.cpp
+++ b/src/rt/rust_gc.cpp
@@ -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);
 }
 
 }