Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
gobjectnotifyqueue.c File Reference
#include <string.h>
#include <glib-object.h>

Go to the source code of this file.

Data Structures

struct  _GObjectNotifyContext
 
struct  _GObjectNotifyQueue
 

Macros

#define __G_OBJECT_NOTIFY_QUEUE_H__
 

Typedefs

typedef typedefG_BEGIN_DECLS struct _GObjectNotifyContext GObjectNotifyContext
 
typedef struct _GObjectNotifyQueue GObjectNotifyQueue
 
typedef void(* GObjectNotifyQueueDispatcher) (GObject *object, guint n_pspecs, GParamSpec **pspecs)
 

Functions

 G_LOCK_DEFINE_STATIC (notify_lock)
 
static void g_object_notify_queue_free (gpointer data)
 
static GObjectNotifyQueueg_object_notify_queue_freeze (GObject *object, GObjectNotifyContext *context)
 
static void g_object_notify_queue_thaw (GObject *object, GObjectNotifyQueue *nqueue)
 
static void g_object_notify_queue_clear (GObject *object G_GNUC_UNUSED, GObjectNotifyQueue *nqueue)
 
static void g_object_notify_queue_add (GObject *object G_GNUC_UNUSED, GObjectNotifyQueue *nqueue, GParamSpec *pspec)
 
static GObjectNotifyQueueg_object_notify_queue_from_object (GObject *object, GObjectNotifyContext *context)
 

Macro Definition Documentation

◆ __G_OBJECT_NOTIFY_QUEUE_H__

#define __G_OBJECT_NOTIFY_QUEUE_H__

Definition at line 28 of file gobjectnotifyqueue.c.

Typedef Documentation

◆ GObjectNotifyContext

typedef typedefG_BEGIN_DECLS struct _GObjectNotifyContext GObjectNotifyContext

Definition at line 38 of file gobjectnotifyqueue.c.

◆ GObjectNotifyQueue

Definition at line 39 of file gobjectnotifyqueue.c.

◆ GObjectNotifyQueueDispatcher

typedef void(* GObjectNotifyQueueDispatcher) (GObject *object, guint n_pspecs, GParamSpec **pspecs)

Definition at line 40 of file gobjectnotifyqueue.c.

Function Documentation

◆ G_LOCK_DEFINE_STATIC()

G_LOCK_DEFINE_STATIC ( notify_lock )

◆ g_object_notify_queue_add()

static void g_object_notify_queue_add ( GObject *object G_GNUC_UNUSED,
GObjectNotifyQueue * nqueue,
GParamSpec * pspec )
inlinestatic

Definition at line 159 of file gobjectnotifyqueue.c.

162{
163 if (pspec->flags & G_PARAM_READABLE)
164 {
165 GParamSpec *redirect;
166
167 G_LOCK(notify_lock);
168
169 g_return_if_fail (nqueue->n_pspecs < 65535);
170
171 redirect = g_param_spec_get_redirect_target (pspec);
172 if (redirect)
173 pspec = redirect;
174
175 /* we do the deduping in _thaw */
176 if (g_slist_find (nqueue->pspecs, pspec) == NULL)
177 {
178 nqueue->pspecs = g_slist_prepend (nqueue->pspecs, pspec);
179 nqueue->n_pspecs++;
180 }
181
182 G_UNLOCK(notify_lock);
183 }
184}
#define NULL
Definition gmacros.h:924
#define g_return_if_fail(expr)
Definition gmessages.h:649
GOBJECT_AVAILABLE_IN_ALL GParamSpec * g_param_spec_get_redirect_target(GParamSpec *pspec)
@ G_PARAM_READABLE
Definition gparam.h:156
GLIB_AVAILABLE_IN_ALL GSList * g_slist_prepend(GSList *list, gpointer data) G_GNUC_WARN_UNUSED_RESULT
GLIB_AVAILABLE_IN_ALL GSList * g_slist_find(GSList *list, gconstpointer data)
#define G_LOCK(name)
Definition gthread.h:137
#define G_UNLOCK(name)
Definition gthread.h:138
GParamFlags flags
Definition gparam.h:212

References _GParamSpec::flags, G_LOCK, G_PARAM_READABLE, g_param_spec_get_redirect_target(), g_return_if_fail, g_slist_find(), g_slist_prepend(), G_UNLOCK, _GObjectNotifyQueue::n_pspecs, NULL, and _GObjectNotifyQueue::pspecs.

◆ g_object_notify_queue_clear()

static void g_object_notify_queue_clear ( GObject *object G_GNUC_UNUSED,
GObjectNotifyQueue * nqueue )
inlinestatic

Definition at line 144 of file gobjectnotifyqueue.c.

146{
147 g_return_if_fail (nqueue->freeze_count > 0);
148
149 G_LOCK(notify_lock);
150
151 g_slist_free (nqueue->pspecs);
152 nqueue->pspecs = NULL;
153 nqueue->n_pspecs = 0;
154
155 G_UNLOCK(notify_lock);
156}
GLIB_AVAILABLE_IN_ALL void g_slist_free(GSList *list)

References _GObjectNotifyQueue::freeze_count, G_LOCK, g_return_if_fail, g_slist_free(), G_UNLOCK, _GObjectNotifyQueue::n_pspecs, NULL, and _GObjectNotifyQueue::pspecs.

◆ g_object_notify_queue_free()

static void g_object_notify_queue_free ( gpointer data)
static

Definition at line 64 of file gobjectnotifyqueue.c.

65{
66 GObjectNotifyQueue *nqueue = data;
67
68 g_slist_free (nqueue->pspecs);
70}
#define g_slice_free(type, mem)
Definition gslice.h:81

References g_slice_free, g_slist_free(), and _GObjectNotifyQueue::pspecs.

Referenced by g_object_notify_queue_freeze().

◆ g_object_notify_queue_freeze()

static GObjectNotifyQueue * g_object_notify_queue_freeze ( GObject * object,
GObjectNotifyContext * context )
inlinestatic

Definition at line 73 of file gobjectnotifyqueue.c.

75{
76 GObjectNotifyQueue *nqueue;
77
78 G_LOCK(notify_lock);
79 nqueue = g_datalist_id_get_data (&object->qdata, context->quark_notify_queue);
80 if (!nqueue)
81 {
83 nqueue->context = context;
84 g_datalist_id_set_data_full (&object->qdata, context->quark_notify_queue,
86 }
87
88 if (nqueue->freeze_count >= 65535)
89 g_critical("Free queue for %s (%p) is larger than 65535,"
90 " called g_object_freeze_notify() too often."
91 " Forgot to call g_object_thaw_notify() or infinite loop",
92 G_OBJECT_TYPE_NAME (object), object);
93 else
94 nqueue->freeze_count++;
95 G_UNLOCK(notify_lock);
96
97 return nqueue;
98}
GLIB_AVAILABLE_IN_ALL void g_datalist_id_set_data_full(GData **datalist, GQuark key_id, gpointer data, GDestroyNotify destroy_func)
GLIB_AVAILABLE_IN_ALL gpointer g_datalist_id_get_data(GData **datalist, GQuark key_id)
#define g_critical(...)
Definition gmessages.h:359
#define G_OBJECT_TYPE_NAME(object)
Definition gobject.h:108
static void g_object_notify_queue_free(gpointer data)
#define g_slice_new0(type)
Definition gslice.h:62
GObjectNotifyContext * context
GData * qdata
Definition gobject.h:258

References _GObjectNotifyQueue::context, _GObjectNotifyQueue::freeze_count, g_critical, g_datalist_id_get_data(), g_datalist_id_set_data_full(), G_LOCK, g_object_notify_queue_free(), G_OBJECT_TYPE_NAME, g_slice_new0, G_UNLOCK, and _GObject::qdata.

◆ g_object_notify_queue_from_object()

static GObjectNotifyQueue * g_object_notify_queue_from_object ( GObject * object,
GObjectNotifyContext * context )
inlinestatic

Definition at line 192 of file gobjectnotifyqueue.c.

194{
195 return g_datalist_id_get_data (&object->qdata, context->quark_notify_queue);
196}

References g_datalist_id_get_data(), and _GObject::qdata.

◆ g_object_notify_queue_thaw()

static void g_object_notify_queue_thaw ( GObject * object,
GObjectNotifyQueue * nqueue )
inlinestatic

Definition at line 101 of file gobjectnotifyqueue.c.

103{
104 GObjectNotifyContext *context = nqueue->context;
105 GParamSpec *pspecs_mem[16], **pspecs, **free_me = NULL;
106 GSList *slist;
107 guint n_pspecs = 0;
108
109 g_return_if_fail (nqueue->freeze_count > 0);
111
112 G_LOCK(notify_lock);
113
114 /* Just make sure we never get into some nasty race condition */
115 if (G_UNLIKELY(nqueue->freeze_count == 0)) {
116 G_UNLOCK(notify_lock);
117 g_critical ("%s: property-changed notification for %s(%p) is not frozen",
118 G_STRFUNC, G_OBJECT_TYPE_NAME (object), object);
119 return;
120 }
121
122 nqueue->freeze_count--;
123 if (nqueue->freeze_count) {
124 G_UNLOCK(notify_lock);
125 return;
126 }
127
128 pspecs = nqueue->n_pspecs > 16 ? free_me = g_new (GParamSpec*, nqueue->n_pspecs) : pspecs_mem;
129
130 for (slist = nqueue->pspecs; slist; slist = slist->next)
131 {
132 pspecs[n_pspecs++] = slist->data;
133 }
134 g_datalist_id_set_data (&object->qdata, context->quark_notify_queue, NULL);
135
136 G_UNLOCK(notify_lock);
137
138 if (n_pspecs)
139 context->dispatcher (object, n_pspecs, pspecs);
140 g_free (free_me);
141}
#define g_atomic_int_get(atomic)
Definition gatomic.h:529
#define g_datalist_id_set_data(dl, q, d)
Definition gdataset.h:104
#define G_STRFUNC
Definition gmacros.h:901
#define G_UNLIKELY(expr)
Definition gmacros.h:1252
GLIB_AVAILABLE_IN_ALL void g_free(gpointer mem)
#define g_new(struct_type, n_structs)
Definition gmem.h:315
typedefG_BEGIN_DECLS struct _GObjectNotifyContext GObjectNotifyContext
typedefG_BEGIN_DECLS struct _GSList GSList
Definition gslist.h:39
unsigned int guint
Definition gtypes.h:61
guint ref_count
Definition gobject.h:257

References _GObjectNotifyQueue::context, _GObjectNotifyQueue::freeze_count, g_atomic_int_get, g_critical, g_datalist_id_set_data, g_free(), G_LOCK, g_new, G_OBJECT_TYPE_NAME, g_return_if_fail, G_STRFUNC, G_UNLIKELY, G_UNLOCK, _GObjectNotifyQueue::n_pspecs, NULL, _GObjectNotifyQueue::pspecs, _GObject::qdata, and _GObject::ref_count.