diff options
author | Marco Trevisan (TreviƱo) <mail@3v1n0.net> | 2021-04-28 01:11:40 +0200 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2021-05-03 21:11:33 -0700 |
commit | 4e7524377ea1a60a878119439c103c1c0db8ac4f (patch) | |
tree | da62a54e687f3e2e534062f05fbfceb1a88ef6e7 /gi/toggle.h | |
parent | 4f0912136971eb0c520f42e45b5915b9fbab55fd (diff) | |
download | gjs-4e7524377ea1a60a878119439c103c1c0db8ac4f.tar.gz |
toggle: Rely on wrapper to cancel finalized objects in queue
While GObject provides native tools to check if an object has been
finalized using GWeakRef's, they have proved to be too fragile for us
because they don't work well when used with toggle references
notifications (not thread safe as glib#2384 demonstrates) and because
may not be cleared on finalization (glib#2390).
So, instead of adding further qdata to monitor a queued object
finalization, let's just ensure that a wrapper cancels the toggle queue
when its wrapped object get finalized.
Since we don't touch the references of the object while adding it to the
queue, we can also ignore remembering the current handled object, as no
recursion can happen now.
It may still happen (mostly due to the way we lock) that a finalized
or unhandled object will be handled by the toggle handler, but this
can't be really fixed for all the racy cases even at enqueue phase
(like in the case a thread enqueues a toggle event just after we've
disassociated the wrapper for such object).
Fixes: #404
Diffstat (limited to 'gi/toggle.h')
-rw-r--r-- | gi/toggle.h | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/gi/toggle.h b/gi/toggle.h index ae7228b8..028dfd80 100644 --- a/gi/toggle.h +++ b/gi/toggle.h @@ -32,9 +32,8 @@ public: private: struct Item { Item() {} - Item(GObject* o, ToggleQueue::Direction d) : gobj(o), direction(d) {} + Item(GObject* o, Direction d) : gobj(o), direction(d) {} GObject *gobj; - GWeakRef weak_ref; ToggleQueue::Direction direction; }; @@ -44,7 +43,6 @@ private: unsigned m_idle_id = 0; Handler m_toggle_handler = nullptr; - std::atomic<GObject*> m_toggling_gobj = nullptr; /* No-op unless GJS_VERBOSE_ENABLE_LIFECYCLE is defined to 1. */ inline void debug(const char* did GJS_USED_VERBOSE_LIFECYCLE, @@ -77,9 +75,6 @@ private: bool handle_toggle(Handler handler); void handle_all_toggles(Handler handler); - /* Checks if the gobj is currently being handled, to avoid recursion */ - bool is_being_handled(GObject* gobj); - /* 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. */ |