[gjs] context: lock access to GC idle



commit d112a7166ae0b60f5f1bf7d7f4b853fda2a6d211
Author: Ray Strode <rstrode redhat com>
Date:   Thu Apr 4 17:08:36 2013 -0400

    context: lock access to GC idle
    
    There's a small race where the GC notification idle id might get
    zeroed before the idle runs, if the GC callback is run from a
    non-main thread.
    
    That means there's the potential for the GC notification idle to
    get dispatched after the context is finalized.
    
    This commit fixes that by protecting access to the idle id with
    a lock.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=670200

 gjs/context.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
---
diff --git a/gjs/context.c b/gjs/context.c
index 20af947..fd122ee 100644
--- a/gjs/context.c
+++ b/gjs/context.c
@@ -98,6 +98,7 @@ enum {
 };
 
 
+static GMutex gc_idle_lock;
 static GMutex contexts_lock;
 static GList *all_contexts = NULL;
 
@@ -878,8 +879,10 @@ gjs_context_idle_emit_gc (gpointer data)
 {
     GjsContext *gjs_context = data;
 
+    g_mutex_lock(&gc_idle_lock);
     gjs_context->idle_emit_gc_id = 0;
-    
+    g_mutex_unlock(&gc_idle_lock);
+
     g_signal_emit (gjs_context, signals[SIGNAL_GC], 0);
     
     return FALSE;
@@ -893,8 +896,10 @@ gjs_on_context_gc (JSRuntime *rt,
     GjsContext *gjs_context = JS_GetContextPrivate(context);
 
     if (status == JSGC_END) {
+        g_mutex_lock(&gc_idle_lock);
         if (gjs_context->idle_emit_gc_id == 0)
             gjs_context->idle_emit_gc_id = g_idle_add (gjs_context_idle_emit_gc, gjs_context);
+        g_mutex_unlock(&gc_idle_lock);
     }
     
     return TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]