diff options
author | Ryan Lortie <desrt@desrt.ca> | 2010-11-08 16:42:32 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2010-11-08 18:21:51 -0500 |
commit | 1a1fc130ece13a442dcacaba1db9108089cead38 (patch) | |
tree | aa341a06c6ad3fa58852be2b7d7435c01b96481c /gobject/gobject.h | |
parent | 78bc8bec4f44a48e5e538f1f9ac9b9e43a9fc833 (diff) |
New function: g_clear_object()
By analogy to g_clear_error, takes a pass-by-reference GObject reference
and, if non-%NULL, unrefs it and sets it equal to %NULL.
Bug #620263.
Diffstat (limited to 'gobject/gobject.h')
-rw-r--r-- | gobject/gobject.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gobject/gobject.h b/gobject/gobject.h index c969b8f50..971f365a6 100644 --- a/gobject/gobject.h +++ b/gobject/gobject.h @@ -562,6 +562,21 @@ G_STMT_START { \ #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \ G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec)) +void g_clear_object (volatile GObject **object_ptr); +#define g_clear_object(object_ptr) \ + G_STMT_START { \ + /* Only one access, please */ \ + gpointer *_p = (gpointer) (object_ptr); \ + gpointer _o; \ + \ + do \ + _o = g_atomic_pointer_get (_p); \ + while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_p, _o, NULL));\ + \ + if (_o) \ + g_object_unref (_o); \ + } G_STMT_END + G_END_DECLS #endif /* __G_OBJECT_H__ */ |