summaryrefslogtreecommitdiff
path: root/gi/toggle.h
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2021-03-29 06:24:24 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2021-04-22 22:58:57 +0200
commit5adb51caa691943d0a516225b2cb5c14f71728ce (patch)
tree01380d47d7d35808a1192bb67fc6ff611730b7b3 /gi/toggle.h
parentc4fc8213b3c0b64b00dcfb26cf140d5924531230 (diff)
downloadgjs-5adb51caa691943d0a516225b2cb5c14f71728ce.tar.gz
object: Do not disassociate a JS object if we have queued toggle up
In case an object has toggle up events queued we need them to happen in order to make the object to be rooted again, and there's no need to disassociate it the object. If instead the object has queued toggle downs, we can instead just cancel them as the object is unrooted anyways, so there's no issue in proceeding. Add test to check whether this is happening, we can simulate such scenario by queuing a further ref on an object from another thread and wait for GC to pick the object. Fixes: #294
Diffstat (limited to 'gi/toggle.h')
-rw-r--r--gi/toggle.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/gi/toggle.h b/gi/toggle.h
index e77c5419..38ad88f6 100644
--- a/gi/toggle.h
+++ b/gi/toggle.h
@@ -31,9 +31,11 @@ public:
private:
struct Item {
+ Item() {}
+ Item(GObject* o, ToggleQueue::Direction d) : gobj(o), direction(d) {}
GObject *gobj;
+ GWeakRef weak_ref;
ToggleQueue::Direction direction;
- unsigned needs_unref : 1;
};
mutable std::mutex lock;
@@ -42,6 +44,7 @@ private:
unsigned m_idle_id;
Handler m_toggle_handler;
+ 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,
@@ -73,6 +76,9 @@ private:
* is empty. */
bool handle_toggle(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. */