Add a free callback to sgen, use it to free our TLS data.
authorZoltan Varga <vargaz@gmail.com>
Wed, 22 Sep 2010 19:18:59 +0000 (21:18 +0200)
committerZoltan Varga <vargaz@gmail.com>
Mon, 3 Jan 2011 14:42:32 +0000 (15:42 +0100)
mono/metadata/gc-internal.h
mono/metadata/sgen-gc.c
mono/mini/mini-gc.c

index 73e8d43b70da6e14470926c6db77aa8b37c2c36f..0fcd369f29caa920f2489ecc3d7ad9b9f9723211 100644 (file)
@@ -250,7 +250,11 @@ typedef struct {
         * needed by the other functions.
         */
        gpointer (*thread_attach_func) (void);
-       /* FIXME: Add a cleanup function too */
+       /* 
+        * Function called during thread deatch to free the data allocated by
+        * thread_attach_func.
+        */
+       void (*thread_detach_func) (gpointer user_data);
        /* 
         * Function called from every thread when suspending for GC. It can save
         * data needed for marking from thread stacks. user_data is the data returned 
index b5057133c11324d1c51378d17fd6ecd88f5d18dc..19ce6ac05c0133176bbf1db1c9e3d617b2628e98 100644 (file)
@@ -5731,6 +5731,12 @@ unregister_current_thread (void)
        } else {
                prev->next = p->next;
        }
+
+       if (gc_callbacks.thread_detach_func) {
+               gc_callbacks.thread_detach_func (p->runtime_data);
+               p->runtime_data = NULL;
+       }
+
        if (p->remset) {
                if (freed_thread_remsets) {
                        for (rset = p->remset; rset->next; rset = rset->next)
index 81e94353d6b31fef066f22517c00db5ed89fc841..e2361634c19f924e91a68cf5b12a931a90e40ae5 100644 (file)
@@ -85,7 +85,6 @@ typedef struct {
  * Contains information collected during the conservative stack marking pass,
  * used during the precise pass. This helps to avoid doing a stack walk twice, which
  * is expensive.
- * FIXME: Optimize memory usage.
  */
 typedef struct {
        guint8 *bitmap;
@@ -467,6 +466,14 @@ thread_attach_func (void)
        return tls;
 }
 
+static void
+thread_detach_func (gpointer user_data)
+{
+       TlsData *tls = user_data;
+
+       g_free (tls);
+}
+
 static void
 thread_suspend_func (gpointer user_data, void *sigctx)
 {
@@ -2093,6 +2100,7 @@ mini_gc_init (void)
 
        memset (&cb, 0, sizeof (cb));
        cb.thread_attach_func = thread_attach_func;
+       cb.thread_detach_func = thread_detach_func;
        cb.thread_suspend_func = thread_suspend_func;
        /* Comment this out to disable precise stack marking */
        cb.thread_mark_func = thread_mark_func;