summaryrefslogtreecommitdiff
path: root/gi/toggle.h
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2018-02-17 23:30:48 -0800
committerPhilip Chimento <philip.chimento@gmail.com>2018-02-18 09:23:02 -0800
commit3fbdb3733e4e554e00b5ff71bd303ffb50a61c6e (patch)
tree0e92e3a86230b228ab8b48e2c0dcac0646cf9edf /gi/toggle.h
parent37588badeb4b5333fd184933f74d4805cea46c1d (diff)
downloadgjs-3fbdb3733e4e554e00b5ff71bd303ffb50a61c6e.tar.gz
context: Shut down toggle queue before dispose notify
This adds a method to shut down the toggle queue so that it doesn't accept any more toggles. This is intended to stop toggles happening that are queued from other threads while the GjsContext dispose sequence has already entered its final garbage collection. We clear pending toggles and shut down the toggle queue before chaining up in GjsContext's dispose function. Sending out dispose notifications causes all GjsMaybeOwned instances to unroot themselves, which means that toggles don't have much meaning after that point. Closes #26.
Diffstat (limited to 'gi/toggle.h')
-rw-r--r--gi/toggle.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/gi/toggle.h b/gi/toggle.h
index b32714ce..f03b6ea4 100644
--- a/gi/toggle.h
+++ b/gi/toggle.h
@@ -26,6 +26,7 @@
#ifndef GJS_TOGGLE_H
#define GJS_TOGGLE_H
+#include <atomic>
#include <deque>
#include <mutex>
#include <glib-object.h>
@@ -53,6 +54,8 @@ private:
std::mutex lock;
std::deque<Item> q;
+ std::atomic_bool m_shutdown = ATOMIC_VAR_INIT(false);
+
unsigned m_idle_id;
Handler m_toggle_handler;
@@ -79,7 +82,12 @@ public:
* want to wait for it to be processed in idle time. Returns false if queue
* is empty. */
bool handle_toggle(Handler handler);
-
+
+ /* After calling this, the toggle queue won't accept any more toggles. Only
+ * intended for use when destroying the JSContext and breaking the
+ * associations between C and JS objects. */
+ void shutdown(void);
+
/* Queues a toggle to be processed in idle time. */
void enqueue(GObject *gobj,
Direction direction,