[gjs/wip/ptomato/develop] WIP - Merge weak_pointer_list and dissociate_list
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/develop] WIP - Merge weak_pointer_list and dissociate_list
- Date: Mon, 18 Sep 2017 16:29:07 +0000 (UTC)
commit d254f14730123032ea4d59c9323911a78615c131
Author: Philip Chimento <philip chimento gmail com>
Date: Mon Sep 18 09:28:31 2017 -0700
WIP - Merge weak_pointer_list and dissociate_list
Needs some sanity checks?
gi/object.cpp | 51 +++++++++++++++++++--------------------------------
1 files changed, 19 insertions(+), 32 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index e801e97..644be71 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -87,12 +87,9 @@ using ParamRefArray = std::vector<ParamRef>;
static std::unordered_map<GType, ParamRefArray> class_init_properties;
static bool weak_pointer_callback = false;
-static std::set<ObjectInstance *> weak_pointer_list;
+static std::set<ObjectInstance *> wrapped_gobject_list;
extern struct JSClass gjs_object_instance_class;
-
-static std::set<ObjectInstance *> dissociate_list;
-
GJS_DEFINE_PRIV_FROM_JS(ObjectInstance, gjs_object_instance_class)
static void disassociate_js_gobject (GObject *gobj);
@@ -158,21 +155,6 @@ throw_priv_is_null_error(JSContext *context)
" up to the parent _init properly?");
}
-static void
-dissociate_list_add(ObjectInstance *priv)
-{
- bool inserted;
- std::tie(std::ignore, inserted) = dissociate_list.insert(priv);
- g_assert(inserted);
-}
-
-static void
-dissociate_list_remove(ObjectInstance *priv)
-{
- size_t erased = dissociate_list.erase(priv);
- g_assert(erased > 0);
-}
-
static ObjectInstance *
get_object_qdata(GObject *gobj)
{
@@ -955,7 +937,7 @@ static void
wrapped_gobj_dispose_notify(gpointer data,
GObject *where_the_object_was)
{
- weak_pointer_list.erase(static_cast<ObjectInstance *>(data));
+ wrapped_gobject_list.erase(static_cast<ObjectInstance *>(data));
#if DEBUG_DISPOSE
gjs_debug(GJS_DEBUG_GOBJECT, "Wrapped GObject %p disposed", where_the_object_was);
#endif
@@ -974,8 +956,7 @@ gobj_no_longer_kept_alive_func(JS::HandleObject obj,
obj.get());
priv->keep_alive.reset();
- dissociate_list_remove(priv);
- weak_pointer_list.erase(priv);
+ wrapped_gobject_list.erase(priv);
}
static void
@@ -993,7 +974,6 @@ handle_toggle_down(GObject *gobj)
if (priv->keep_alive.rooted()) {
gjs_debug_lifecycle(GJS_DEBUG_GOBJECT, "Removing object from keep alive");
priv->keep_alive.switch_to_unrooted();
- dissociate_list_remove(priv);
}
}
@@ -1023,7 +1003,6 @@ handle_toggle_up(GObject *gobj)
gjs_debug_lifecycle(GJS_DEBUG_GOBJECT, "Adding object to keep alive");
auto cx = static_cast<JSContext *>(gjs_context_get_native_context(context));
priv->keep_alive.switch_to_rooted(cx, gobj_no_longer_kept_alive_func, priv);
- dissociate_list_add(priv);
}
}
@@ -1161,9 +1140,18 @@ gjs_object_prepare_shutdown(void)
* toggle ref removal -> gobj dispose -> toggle ref notify
* by simply ignoring toggle ref notifications during this process.
*/
- for (auto iter : dissociate_list)
- release_native_object(iter);
- dissociate_list.clear();
+ std::vector<ObjectInstance *> to_be_released;
+ for (auto iter = wrapped_gobject_list.begin(); iter != wrapped_gobject_list.end(); ) {
+ ObjectInstance *priv = *iter;
+ if (priv->keep_alive.rooted()) {
+ to_be_released.push_back(priv);
+ iter = wrapped_gobject_list.erase(iter);
+ } else {
+ iter++;
+ }
+ }
+ for (ObjectInstance *priv : to_be_released)
+ release_native_object(priv);
}
static ObjectInstance *
@@ -1206,7 +1194,7 @@ update_heap_wrapper_weak_pointers(JSContext *cx,
{
std::vector<GObject *> to_be_disassociated;
- for (auto iter = weak_pointer_list.begin(); iter != weak_pointer_list.end(); ) {
+ for (auto iter = wrapped_gobject_list.begin(); iter != wrapped_gobject_list.end(); ) {
ObjectInstance *priv = *iter;
if (priv->keep_alive.rooted() || priv->keep_alive == nullptr ||
!priv->keep_alive.update_after_gc()) {
@@ -1218,7 +1206,7 @@ update_heap_wrapper_weak_pointers(JSContext *cx,
* may also cause it to be erased.)
*/
to_be_disassociated.push_back(priv->gobj);
- iter = weak_pointer_list.erase(iter);
+ iter = wrapped_gobject_list.erase(iter);
}
}
@@ -1254,7 +1242,7 @@ associate_js_gobject (JSContext *context,
priv->keep_alive = object;
ensure_weak_pointer_callback(context);
- weak_pointer_list.insert(priv);
+ wrapped_gobject_list.insert(priv);
g_object_weak_ref(gobj, wrapped_gobj_dispose_notify, priv);
}
@@ -1281,7 +1269,6 @@ ensure_uses_toggle_ref(JSContext *cx,
*/
priv->uses_toggle_ref = true;
priv->keep_alive.switch_to_rooted(cx, gobj_no_longer_kept_alive_func, priv);
- dissociate_list_add(priv);
g_object_add_toggle_ref(priv->gobj, wrapped_gobj_toggle_notify, nullptr);
/* We now have both a ref and a toggle ref, we only want the toggle ref.
@@ -1545,8 +1532,8 @@ object_instance_finalize(JSFreeOp *fop,
"Removing from keep alive");
priv->keep_alive.reset();
- dissociate_list_remove(priv);
}
+ wrapped_gobject_list.erase(priv);
if (priv->info) {
g_base_info_unref( (GIBaseInfo*) priv->info);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]