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




commit 85fae3b0bb001a1c74331c2a25902ac00c200ebe
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 f8524e84..0c40ee6e 100644
--- a/gjs/context-private.h
+++ b/gjs/context-private.h
@@ -226,7 +226,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 30d79823..63924525 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -618,6 +618,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:
  *
@@ -625,6 +630,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]