[gjs: 2/12] function: Use gatomicrefcount for trampoline refcounting
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 2/12] function: Use gatomicrefcount for trampoline refcounting
- Date: Sun, 20 Sep 2020 22:13:03 +0000 (UTC)
commit e2f9cf808fd3672f14326befabc3d523842c7d7e
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Wed Sep 2 19:35:43 2020 +0200
function: Use gatomicrefcount for trampoline refcounting
Since we depend on GLib 2.58 that includes this, let's just use it
gi/function.cpp | 9 +++------
gi/function.h | 3 ++-
2 files changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index f3408da4..b0cb101b 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -93,17 +93,14 @@ GJS_DEFINE_PRIV_FROM_JS(Function, gjs_function_class)
GjsCallbackTrampoline* gjs_callback_trampoline_ref(
GjsCallbackTrampoline* trampoline) {
- trampoline->ref_count++;
+ g_atomic_ref_count_inc(&trampoline->ref_count);
return trampoline;
}
void
gjs_callback_trampoline_unref(GjsCallbackTrampoline *trampoline)
{
- /* Not MT-safe, like all the rest of GJS */
-
- trampoline->ref_count--;
- if (trampoline->ref_count == 0) {
+ if (g_atomic_ref_count_dec(&trampoline->ref_count)) {
g_clear_pointer(&trampoline->js_function, g_closure_unref);
if (trampoline->info && trampoline->closure)
g_callable_info_free_closure(trampoline->info, trampoline->closure);
@@ -550,7 +547,7 @@ GjsCallbackTrampoline* gjs_callback_trampoline_new(
trampoline = g_new(GjsCallbackTrampoline, 1);
new (trampoline) GjsCallbackTrampoline();
- trampoline->ref_count = 1;
+ g_atomic_ref_count_init(&trampoline->ref_count);
trampoline->info = callable_info;
g_base_info_ref((GIBaseInfo*)trampoline->info);
diff --git a/gi/function.h b/gi/function.h
index 2b2ea106..98d09d0f 100644
--- a/gi/function.h
+++ b/gi/function.h
@@ -29,6 +29,7 @@
#include <ffi.h>
#include <girepository.h>
#include <glib-object.h>
+#include <glib.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
@@ -48,7 +49,7 @@ typedef enum {
} GjsParamType;
struct GjsCallbackTrampoline {
- int ref_count;
+ gatomicrefcount ref_count;
GICallableInfo *info;
GClosure *js_function;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]