[gjs/297-prevent-accumulating-toggles] context: Clear toggle queue whenever a GC is scheduled




commit bdc78cb90619ef6126419ceac5b11c21572ae698
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Aug 9 15:37:16 2020 -0700

    context: Clear toggle queue whenever a GC is scheduled
    
    It seems that occasionally when using a GFileMonitor, toggle queue
    notifications will arrive on a separate thread and get queued, faster
    than they can be processed.
    
    This ensures the toggle queue is drained every time we finish executing
    JS code, which will hopefully make such a pile-up less likely.
    
    Closes: #297

 gjs/context-private.h | 2 +-
 gjs/context.cpp       | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/gjs/context-private.h b/gjs/context-private.h
index ef8f28b6..3e33bb1a 100644
--- a/gjs/context-private.h
+++ b/gjs/context-private.h
@@ -228,7 +228,7 @@ class GjsContextPrivate : public JS::JobQueue {
                        const JS::HandleValueArray& args,
                        JS::MutableHandleValue rval);
 
-    void schedule_gc(void) { schedule_gc_internal(true); }
+    void schedule_gc();
     void schedule_gc_if_needed(void);
 
     void exit(uint8_t exit_code);
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 747f6f38..58c43820 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -616,6 +616,11 @@ void GjsContextPrivate::schedule_gc_internal(bool force_gc) {
                                               nullptr);
 }
 
+void GjsContextPrivate::schedule_gc() {
+    gjs_object_clear_toggles();
+    schedule_gc_internal(true);
+}
+
 /*
  * GjsContextPrivate::schedule_gc_if_needed:
  *
@@ -623,6 +628,8 @@ void GjsContextPrivate::schedule_gc_internal(bool force_gc) {
  * schedules a full GC in the next idle time.
  */
 void GjsContextPrivate::schedule_gc_if_needed(void) {
+    gjs_object_clear_toggles();
+
     // We call JS_MaybeGC immediately, but defer a check for a full GC cycle
     // to an idle handler.
     JS_MaybeGC(m_cx);


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