reverted notify_mutex introduction, since this prevents parallelized

Sat Jul 30 21:10:26 2005  Tim Janik  <timj@gtk.org>

        * gobject.c: reverted notify_mutex introduction, since this prevents
        parallelized setting of object properties on different objects, and
        serves no apparent purpose (to me at least).
        g_object_real_dispose(): removed non-atomic reference count
        modifications.
        g_object_unref(): make sure the closures array is destroyed when
        destroying signal handlers.

        * gparam.c: cosmetic changes.

        * gsignal.c: comment fixup. allow 16bit blocking count.

        * gsignal.c: reverted GClosure related changes.

        * gclosure.c: reverted premature commit of atomic reference
        counting attempt.
This commit is contained in:
Tim Janik 2005-07-30 19:46:11 +00:00 committed by Tim Janik
parent 84132e9298
commit f0cfc267ba
5 changed files with 181 additions and 380 deletions

View File

@ -1,3 +1,22 @@
Sat Jul 30 21:10:26 2005 Tim Janik <timj@gtk.org>
* gobject.c: reverted notify_mutex introduction, since this prevents
parallelized setting of object properties on different objects, and
serves no apparent purpose (to me at least).
g_object_real_dispose(): removed non-atomic reference count
modifications.
g_object_unref(): make sure the closures array is destroyed when
destroying signal handlers.
* gparam.c: cosmetic changes.
* gsignal.c: comment fixup. allow 16bit blocking count.
* gsignal.c: reverted GClosure related changes.
* gclosure.c: reverted premature commit of atomic reference
counting attempt.
2005-07-21 Matthias Clasen <mclasen@redhat.com> 2005-07-21 Matthias Clasen <mclasen@redhat.com>
* === Released 2.7.4 === * === Released 2.7.4 ===

View File

@ -36,44 +36,6 @@
#define CLOSURE_N_NOTIFIERS(cl) (CLOSURE_N_MFUNCS (cl) + \ #define CLOSURE_N_NOTIFIERS(cl) (CLOSURE_N_MFUNCS (cl) + \
(cl)->n_fnotifiers + \ (cl)->n_fnotifiers + \
(cl)->n_inotifiers) (cl)->n_inotifiers)
/* union of first int we need to make atomic */
typedef union {
GClosure bits;
gint atomic;
} GAtomicClosureBits;
#define BITS_AS_INT(b) (((GAtomicClosureBits*)(b))->atomic)
#define CLOSURE_READ_BITS(cl,bits) (BITS_AS_INT(bits) = g_atomic_int_get ((gint*)(cl)))
#define CLOSURE_READ_BITS2(cl,old,new) (BITS_AS_INT(old) = CLOSURE_READ_BITS (cl, new))
#define CLOSURE_SWAP_BITS(cl,old,new) (g_atomic_int_compare_and_exchange ((gint*)(cl), \
BITS_AS_INT(old),BITS_AS_INT(new)))
#define CLOSURE_REF(closure) \
G_STMT_START { \
GClosure old, new; \
do { \
CLOSURE_READ_BITS2 (closure, &old, &new); \
new.ref_count++; \
} \
while (!CLOSURE_SWAP_BITS (closure, &old, &new)); \
} G_STMT_END
#define CLOSURE_UNREF(closure, is_zero) \
G_STMT_START { \
GClosure old, new; \
do { \
CLOSURE_READ_BITS2 (closure, &old, &new); \
if (old.ref_count == 1) /* last unref, invalidate first */ \
g_closure_invalidate ((closure)); \
new.ref_count--; \
is_zero = (new.ref_count == 0); \
} \
while (!CLOSURE_SWAP_BITS (closure, &old, &new)); \
} G_STMT_END
enum { enum {
FNOTIFY, FNOTIFY,
INOTIFY, INOTIFY,
@ -114,8 +76,6 @@ static inline void
closure_invoke_notifiers (GClosure *closure, closure_invoke_notifiers (GClosure *closure,
guint notify_type) guint notify_type)
{ {
GClosure bits, new;
/* notifier layout: /* notifier layout:
* meta_marshal n_guards n_guards n_fnotif. n_inotifiers * meta_marshal n_guards n_guards n_fnotif. n_inotifiers
* ->[[meta_marshal][pre_guards][post_guards][fnotifiers][inotifiers]] * ->[[meta_marshal][pre_guards][post_guards][fnotifiers][inotifiers]]
@ -139,12 +99,11 @@ closure_invoke_notifiers (GClosure *closure,
GClosureNotifyData *ndata; GClosureNotifyData *ndata;
guint i, offs; guint i, offs;
case FNOTIFY: case FNOTIFY:
CLOSURE_READ_BITS (closure, &bits); while (closure->n_fnotifiers)
while (bits.n_fnotifiers)
{ {
register guint n = --bits.n_fnotifiers; register guint n = --closure->n_fnotifiers;
ndata = closure->notifiers + CLOSURE_N_MFUNCS (&bits) + n; ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + n;
closure->marshal = (GClosureMarshal) ndata->notify; closure->marshal = (GClosureMarshal) ndata->notify;
closure->data = ndata->data; closure->data = ndata->data;
ndata->notify (ndata->data, closure); ndata->notify (ndata->data, closure);
@ -153,34 +112,23 @@ closure_invoke_notifiers (GClosure *closure,
closure->data = NULL; closure->data = NULL;
break; break;
case INOTIFY: case INOTIFY:
do { closure->in_inotify = TRUE;
CLOSURE_READ_BITS2 (closure, &bits, &new); while (closure->n_inotifiers)
new.in_inotify = TRUE;
}
while (!CLOSURE_SWAP_BITS (closure, &bits, &new));
while (bits.n_inotifiers)
{ {
register guint n = --bits.n_inotifiers; register guint n = --closure->n_inotifiers;
ndata = closure->notifiers + CLOSURE_N_MFUNCS (&bits) + bits.n_fnotifiers + n; ndata = closure->notifiers + CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + n;
closure->marshal = (GClosureMarshal) ndata->notify; closure->marshal = (GClosureMarshal) ndata->notify;
closure->data = ndata->data; closure->data = ndata->data;
ndata->notify (ndata->data, closure); ndata->notify (ndata->data, closure);
} }
closure->marshal = NULL; closure->marshal = NULL;
closure->data = NULL; closure->data = NULL;
do { closure->in_inotify = FALSE;
CLOSURE_READ_BITS2 (closure, &bits, &new);
new.n_inotifiers = 0;
new.in_inotify = FALSE;
}
while (!CLOSURE_SWAP_BITS (closure, &bits, &new));
break; break;
case PRE_NOTIFY: case PRE_NOTIFY:
CLOSURE_READ_BITS (closure, &bits); i = closure->n_guards;
i = bits.n_guards; offs = closure->meta_marshal;
offs = bits.meta_marshal;
while (i--) while (i--)
{ {
ndata = closure->notifiers + offs + i; ndata = closure->notifiers + offs + i;
@ -188,9 +136,8 @@ closure_invoke_notifiers (GClosure *closure,
} }
break; break;
case POST_NOTIFY: case POST_NOTIFY:
CLOSURE_READ_BITS (closure, &bits); i = closure->n_guards;
i = bits.n_guards; offs = closure->meta_marshal + i;
offs = bits.meta_marshal + i;
while (i--) while (i--)
{ {
ndata = closure->notifiers + offs + i; ndata = closure->notifiers + offs + i;
@ -205,48 +152,29 @@ g_closure_set_meta_marshal (GClosure *closure,
gpointer marshal_data, gpointer marshal_data,
GClosureMarshal meta_marshal) GClosureMarshal meta_marshal)
{ {
GClosureNotifyData *old_notifiers, *new_notifiers; GClosureNotifyData *notifiers;
guint n; guint n;
GClosure old, new;
g_return_if_fail (closure != NULL); g_return_if_fail (closure != NULL);
g_return_if_fail (meta_marshal != NULL); g_return_if_fail (meta_marshal != NULL);
g_return_if_fail (closure->is_invalid == FALSE);
g_return_if_fail (closure->in_marshal == FALSE);
g_return_if_fail (closure->meta_marshal == 0);
retry: n = CLOSURE_N_NOTIFIERS (closure);
CLOSURE_READ_BITS2 (closure, &old, &new); notifiers = closure->notifiers;
closure->notifiers = g_renew (GClosureNotifyData, NULL, CLOSURE_N_NOTIFIERS (closure) + 1);
g_return_if_fail (old.is_invalid == FALSE); if (notifiers)
g_return_if_fail (old.in_marshal == FALSE);
g_return_if_fail (old.meta_marshal == 0);
n = CLOSURE_N_NOTIFIERS (&old);
old_notifiers = closure->notifiers;
new_notifiers = g_renew (GClosureNotifyData, NULL, n + 1);
if (old_notifiers)
{ {
/* usually the meta marshal will be setup right after creation, so the /* usually the meta marshal will be setup right after creation, so the
* g_memmove() should be rare-case scenario * g_memmove() should be rare-case scenario
*/ */
g_memmove (new_notifiers + 1, old_notifiers, n * sizeof (old_notifiers[0])); g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
g_free (notifiers);
} }
new_notifiers[0].data = marshal_data; closure->notifiers[0].data = marshal_data;
new_notifiers[0].notify = (GClosureNotify) meta_marshal; closure->notifiers[0].notify = (GClosureNotify) meta_marshal;
closure->meta_marshal = 1;
new.meta_marshal = 1;
/* this cannot be made atomic, as soon as we switch on the meta_marshal
* bit, another thread could use the notifier while we have not yet
* copied it. the safest is to install the new_notifiers first and then
* switch on the meta_marshal flag. */
closure->notifiers = new_notifiers;
if (!CLOSURE_SWAP_BITS (closure, &old, &new)) {
g_free (new_notifiers);
goto retry;
}
g_free (old_notifiers);
} }
void void
@ -257,56 +185,40 @@ g_closure_add_marshal_guards (GClosure *closure,
GClosureNotify post_marshal_notify) GClosureNotify post_marshal_notify)
{ {
guint i; guint i;
GClosure old, new;
GClosureNotifyData *old_notifiers, *new_notifiers;
g_return_if_fail (closure != NULL); g_return_if_fail (closure != NULL);
g_return_if_fail (pre_marshal_notify != NULL); g_return_if_fail (pre_marshal_notify != NULL);
g_return_if_fail (post_marshal_notify != NULL); g_return_if_fail (post_marshal_notify != NULL);
g_return_if_fail (closure->is_invalid == FALSE);
g_return_if_fail (closure->in_marshal == FALSE);
g_return_if_fail (closure->n_guards < CLOSURE_MAX_N_GUARDS);
retry: closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 2);
CLOSURE_READ_BITS2 (closure, &old, &new); if (closure->n_inotifiers)
closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
g_return_if_fail (old.is_invalid == FALSE); closure->n_fnotifiers +
g_return_if_fail (old.in_marshal == FALSE); closure->n_inotifiers + 1)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
g_return_if_fail (old.n_guards < CLOSURE_MAX_N_GUARDS); closure->n_fnotifiers + 0)];
if (closure->n_inotifiers > 1)
old_notifiers = closure->notifiers; closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
new_notifiers = g_renew (GClosureNotifyData, old_notifiers, CLOSURE_N_NOTIFIERS (&old) + 2); closure->n_fnotifiers +
if (old.n_inotifiers) closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
new_notifiers[(CLOSURE_N_MFUNCS (&old) + closure->n_fnotifiers + 1)];
old.n_fnotifiers + if (closure->n_fnotifiers)
old.n_inotifiers + 1)] = new_notifiers[(CLOSURE_N_MFUNCS (&old) + closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
old.n_fnotifiers + 0)]; closure->n_fnotifiers + 1)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 0];
if (old.n_inotifiers > 1) if (closure->n_fnotifiers > 1)
new_notifiers[(CLOSURE_N_MFUNCS (&old) + closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
old.n_fnotifiers + closure->n_fnotifiers)] = closure->notifiers[CLOSURE_N_MFUNCS (closure) + 1];
old.n_inotifiers)] = new_notifiers[(CLOSURE_N_MFUNCS (&old) + if (closure->n_guards)
old.n_fnotifiers + 1)]; closure->notifiers[(closure->meta_marshal +
if (old.n_fnotifiers) closure->n_guards +
new_notifiers[(CLOSURE_N_MFUNCS (&old) + closure->n_guards + 1)] = closure->notifiers[closure->meta_marshal + closure->n_guards];
old.n_fnotifiers + 1)] = new_notifiers[CLOSURE_N_MFUNCS (&old) + 0]; i = closure->n_guards++;
if (old.n_fnotifiers > 1) closure->notifiers[closure->meta_marshal + i].data = pre_marshal_data;
new_notifiers[(CLOSURE_N_MFUNCS (&old) + closure->notifiers[closure->meta_marshal + i].notify = pre_marshal_notify;
old.n_fnotifiers)] = new_notifiers[CLOSURE_N_MFUNCS (&old) + 1]; closure->notifiers[closure->meta_marshal + i + 1].data = post_marshal_data;
if (old.n_guards) closure->notifiers[closure->meta_marshal + i + 1].notify = post_marshal_notify;
new_notifiers[(old.meta_marshal +
old.n_guards +
old.n_guards + 1)] = new_notifiers[old.meta_marshal + old.n_guards];
i = old.n_guards;
new.n_guards = i+1;
new_notifiers[old.meta_marshal + i].data = pre_marshal_data;
new_notifiers[old.meta_marshal + i].notify = pre_marshal_notify;
new_notifiers[old.meta_marshal + i + 1].data = post_marshal_data;
new_notifiers[old.meta_marshal + i + 1].notify = post_marshal_notify;
/* not really atomic */
closure->notifiers = new_notifiers;
if (!CLOSURE_SWAP_BITS (closure, &old, &new))
goto retry;
} }
void void
@ -315,35 +227,20 @@ g_closure_add_finalize_notifier (GClosure *closure,
GClosureNotify notify_func) GClosureNotify notify_func)
{ {
guint i; guint i;
GClosure old, new;
GClosureNotifyData *old_notifiers, *new_notifiers;
g_return_if_fail (closure != NULL); g_return_if_fail (closure != NULL);
g_return_if_fail (notify_func != NULL); g_return_if_fail (notify_func != NULL);
g_return_if_fail (closure->n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS);
retry: closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
CLOSURE_READ_BITS2 (closure, &old, &new); if (closure->n_inotifiers)
closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
g_return_if_fail (old.n_fnotifiers < CLOSURE_MAX_N_FNOTIFIERS); closure->n_fnotifiers +
closure->n_inotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
old_notifiers = closure->notifiers; closure->n_fnotifiers + 0)];
new_notifiers = g_renew (GClosureNotifyData, old_notifiers, CLOSURE_N_NOTIFIERS (&old) + 1); i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers++;
if (old.n_inotifiers) closure->notifiers[i].data = notify_data;
new_notifiers[(CLOSURE_N_MFUNCS (&old) + closure->notifiers[i].notify = notify_func;
old.n_fnotifiers +
old.n_inotifiers)] = new_notifiers[(CLOSURE_N_MFUNCS (&old) +
old.n_fnotifiers + 0)];
i = CLOSURE_N_MFUNCS (&old) + old.n_fnotifiers;
new.n_fnotifiers++;
new_notifiers[i].data = notify_data;
new_notifiers[i].notify = notify_func;
/* not really atomic */
closure->notifiers = new_notifiers;
while (!CLOSURE_SWAP_BITS (closure, &old, &new))
goto retry;
} }
void void
@ -352,31 +249,16 @@ g_closure_add_invalidate_notifier (GClosure *closure,
GClosureNotify notify_func) GClosureNotify notify_func)
{ {
guint i; guint i;
GClosure old, new;
GClosureNotifyData *old_notifiers, *new_notifiers;
g_return_if_fail (closure != NULL); g_return_if_fail (closure != NULL);
g_return_if_fail (notify_func != NULL); g_return_if_fail (notify_func != NULL);
g_return_if_fail (closure->is_invalid == FALSE);
g_return_if_fail (closure->n_inotifiers < CLOSURE_MAX_N_INOTIFIERS);
retry: closure->notifiers = g_renew (GClosureNotifyData, closure->notifiers, CLOSURE_N_NOTIFIERS (closure) + 1);
CLOSURE_READ_BITS2 (closure, &old, &new); i = CLOSURE_N_MFUNCS (closure) + closure->n_fnotifiers + closure->n_inotifiers++;
closure->notifiers[i].data = notify_data;
g_return_if_fail (old.is_invalid == FALSE); closure->notifiers[i].notify = notify_func;
g_return_if_fail (old.n_inotifiers < CLOSURE_MAX_N_INOTIFIERS);
old_notifiers = closure->notifiers;
new_notifiers = g_renew (GClosureNotifyData, old_notifiers, CLOSURE_N_NOTIFIERS (&old) + 1);
i = CLOSURE_N_MFUNCS (&old) + old.n_fnotifiers + old.n_inotifiers;
new.n_inotifiers++;
new_notifiers[i].data = notify_data;
new_notifiers[i].notify = notify_func;
/* not really atomic */
closure->notifiers = new_notifiers;
while (!CLOSURE_SWAP_BITS (closure, &old, &new))
goto retry;
} }
static inline gboolean static inline gboolean
@ -385,19 +267,12 @@ closure_try_remove_inotify (GClosure *closure,
GClosureNotify notify_func) GClosureNotify notify_func)
{ {
GClosureNotifyData *ndata, *nlast; GClosureNotifyData *ndata, *nlast;
GClosure old, new;
retry: nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - 1;
CLOSURE_READ_BITS2 (closure, &old, &new); for (ndata = nlast + 1 - closure->n_inotifiers; ndata <= nlast; ndata++)
nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (&old) - 1;
for (ndata = nlast + 1 - old.n_inotifiers; ndata <= nlast; ndata++)
if (ndata->notify == notify_func && ndata->data == notify_data) if (ndata->notify == notify_func && ndata->data == notify_data)
{ {
new.n_inotifiers -= 1; closure->n_inotifiers -= 1;
if (!CLOSURE_SWAP_BITS (closure, &old, &new))
goto retry;
if (ndata < nlast) if (ndata < nlast)
*ndata = *nlast; *ndata = *nlast;
@ -412,27 +287,19 @@ closure_try_remove_fnotify (GClosure *closure,
GClosureNotify notify_func) GClosureNotify notify_func)
{ {
GClosureNotifyData *ndata, *nlast; GClosureNotifyData *ndata, *nlast;
GClosure old, new;
retry: nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (closure) - closure->n_inotifiers - 1;
CLOSURE_READ_BITS2 (closure, &old, &new); for (ndata = nlast + 1 - closure->n_fnotifiers; ndata <= nlast; ndata++)
nlast = closure->notifiers + CLOSURE_N_NOTIFIERS (&old) - old.n_inotifiers - 1;
for (ndata = nlast + 1 - old.n_fnotifiers; ndata <= nlast; ndata++)
if (ndata->notify == notify_func && ndata->data == notify_data) if (ndata->notify == notify_func && ndata->data == notify_data)
{ {
new.n_fnotifiers -= 1; closure->n_fnotifiers -= 1;
if (!CLOSURE_SWAP_BITS (closure, &old, &new))
goto retry;
if (ndata < nlast) if (ndata < nlast)
*ndata = *nlast; *ndata = *nlast;
if (closure->n_inotifiers)
if (new.n_inotifiers) closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
closure->notifiers[(CLOSURE_N_MFUNCS (&new) + closure->n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (closure) +
new.n_fnotifiers)] = closure->notifiers[(CLOSURE_N_MFUNCS (&new) + closure->n_fnotifiers +
new.n_fnotifiers + closure->n_inotifiers)];
new.n_inotifiers)];
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -445,7 +312,7 @@ g_closure_ref (GClosure *closure)
g_return_val_if_fail (closure->ref_count > 0, NULL); g_return_val_if_fail (closure->ref_count > 0, NULL);
g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL); g_return_val_if_fail (closure->ref_count < CLOSURE_MAX_REF_COUNT, NULL);
CLOSURE_REF (closure); closure->ref_count += 1;
return closure; return closure;
} }
@ -453,21 +320,12 @@ g_closure_ref (GClosure *closure)
void void
g_closure_invalidate (GClosure *closure) g_closure_invalidate (GClosure *closure)
{ {
GClosure old, new;
g_return_if_fail (closure != NULL); g_return_if_fail (closure != NULL);
retry: if (!closure->is_invalid)
CLOSURE_READ_BITS2 (closure, &old, &new);
if (!old.is_invalid)
{ {
new.ref_count++; closure->ref_count += 1; /* preserve floating flag */
new.is_invalid = TRUE; closure->is_invalid = TRUE;
if (!CLOSURE_SWAP_BITS (closure, &old, &new))
goto retry;
closure_invoke_notifiers (closure, INOTIFY); closure_invoke_notifiers (closure, INOTIFY);
g_closure_unref (closure); g_closure_unref (closure);
} }
@ -476,14 +334,15 @@ retry:
void void
g_closure_unref (GClosure *closure) g_closure_unref (GClosure *closure)
{ {
gboolean is_zero;
g_return_if_fail (closure != NULL); g_return_if_fail (closure != NULL);
g_return_if_fail (closure->ref_count > 0); g_return_if_fail (closure->ref_count > 0);
CLOSURE_UNREF (closure, is_zero); if (closure->ref_count == 1) /* last unref, invalidate first */
g_closure_invalidate (closure);
if (G_UNLIKELY (is_zero)) closure->ref_count -= 1;
if (closure->ref_count == 0)
{ {
closure_invoke_notifiers (closure, FNOTIFY); closure_invoke_notifiers (closure, FNOTIFY);
g_free (closure->notifiers); g_free (closure->notifiers);
@ -494,8 +353,6 @@ g_closure_unref (GClosure *closure)
void void
g_closure_sink (GClosure *closure) g_closure_sink (GClosure *closure)
{ {
GClosure old, new;
g_return_if_fail (closure != NULL); g_return_if_fail (closure != NULL);
g_return_if_fail (closure->ref_count > 0); g_return_if_fail (closure->ref_count > 0);
@ -504,17 +361,13 @@ g_closure_sink (GClosure *closure)
* is unowned. with invoking g_closure_sink() code may * is unowned. with invoking g_closure_sink() code may
* indicate that it takes over that intiial ref_count. * indicate that it takes over that intiial ref_count.
*/ */
retry: if (closure->floating)
CLOSURE_READ_BITS2 (closure, &old, &new);
if (old.floating)
{ {
new.floating = FALSE; closure->floating = FALSE;
if (closure->ref_count > 1)
if (!CLOSURE_SWAP_BITS (closure, &old, &new)) closure->ref_count -= 1;
goto retry; else
g_closure_unref (closure);
g_closure_unref (closure);
} }
} }
@ -523,14 +376,10 @@ g_closure_remove_invalidate_notifier (GClosure *closure,
gpointer notify_data, gpointer notify_data,
GClosureNotify notify_func) GClosureNotify notify_func)
{ {
GClosure bits;
g_return_if_fail (closure != NULL); g_return_if_fail (closure != NULL);
g_return_if_fail (notify_func != NULL); g_return_if_fail (notify_func != NULL);
CLOSURE_READ_BITS (closure, &bits); if (closure->is_invalid && closure->in_inotify && /* account removal of notify_func() while its called */
if (bits.is_invalid && bits.in_inotify && /* account removal of notify_func() while its called */
((gpointer) closure->marshal) == ((gpointer) notify_func) && closure->data == notify_data) ((gpointer) closure->marshal) == ((gpointer) notify_func) && closure->data == notify_data)
closure->marshal = NULL; closure->marshal = NULL;
else if (!closure_try_remove_inotify (closure, notify_data, notify_func)) else if (!closure_try_remove_inotify (closure, notify_data, notify_func))
@ -543,14 +392,10 @@ g_closure_remove_finalize_notifier (GClosure *closure,
gpointer notify_data, gpointer notify_data,
GClosureNotify notify_func) GClosureNotify notify_func)
{ {
GClosure bits;
g_return_if_fail (closure != NULL); g_return_if_fail (closure != NULL);
g_return_if_fail (notify_func != NULL); g_return_if_fail (notify_func != NULL);
CLOSURE_READ_BITS (closure, &bits); if (closure->is_invalid && !closure->in_inotify && /* account removal of notify_func() while its called */
if (bits.is_invalid && !bits.in_inotify && /* account removal of notify_func() while its called */
((gpointer) closure->marshal) == ((gpointer) notify_func) && closure->data == notify_data) ((gpointer) closure->marshal) == ((gpointer) notify_func) && closure->data == notify_data)
closure->marshal = NULL; closure->marshal = NULL;
else if (!closure_try_remove_fnotify (closure, notify_data, notify_func)) else if (!closure_try_remove_fnotify (closure, notify_data, notify_func))
@ -565,29 +410,19 @@ g_closure_invoke (GClosure *closure,
const GValue *param_values, const GValue *param_values,
gpointer invocation_hint) gpointer invocation_hint)
{ {
GClosure old, new;
g_return_if_fail (closure != NULL); g_return_if_fail (closure != NULL);
retry: if (!closure->is_invalid)
CLOSURE_READ_BITS2 (closure, &old, &new); {
if (!old.is_invalid)
{
GClosureMarshal marshal; GClosureMarshal marshal;
gpointer marshal_data; gpointer marshal_data;
gboolean in_marshal = old.in_marshal; gboolean in_marshal = closure->in_marshal;
gboolean meta_marshal = old.meta_marshal;
g_return_if_fail (closure->marshal || meta_marshal); g_return_if_fail (closure->marshal || closure->meta_marshal);
new.ref_count++; closure->ref_count += 1; /* preserve floating flag */
new.in_marshal = TRUE; closure->in_marshal = TRUE;
if (closure->meta_marshal)
if (!CLOSURE_SWAP_BITS (closure, &old, &new))
goto retry;
if (meta_marshal)
{ {
marshal_data = closure->notifiers[0].data; marshal_data = closure->notifiers[0].data;
marshal = (GClosureMarshal) closure->notifiers[0].notify; marshal = (GClosureMarshal) closure->notifiers[0].notify;
@ -599,22 +434,15 @@ retry:
} }
if (!in_marshal) if (!in_marshal)
closure_invoke_notifiers (closure, PRE_NOTIFY); closure_invoke_notifiers (closure, PRE_NOTIFY);
marshal (closure, marshal (closure,
return_value, return_value,
n_param_values, param_values, n_param_values, param_values,
invocation_hint, invocation_hint,
marshal_data); marshal_data);
if (!in_marshal) if (!in_marshal)
closure_invoke_notifiers (closure, POST_NOTIFY); closure_invoke_notifiers (closure, POST_NOTIFY);
closure->in_marshal = in_marshal;
do { g_closure_unref (closure);
CLOSURE_READ_BITS2 (closure, &old, &new);
new.in_marshal = in_marshal;
new.ref_count--;
}
while (!CLOSURE_SWAP_BITS (closure, &old, &new));
} }
} }

View File

@ -116,8 +116,6 @@ static gulong gobject_signals[LAST_SIGNAL] = { 0, };
G_LOCK_DEFINE_STATIC (construct_objects_lock); G_LOCK_DEFINE_STATIC (construct_objects_lock);
static GSList *construct_objects = NULL; static GSList *construct_objects = NULL;
static GStaticRecMutex notify_mutex = G_STATIC_REC_MUTEX_INIT;
/* --- functions --- */ /* --- functions --- */
#ifdef G_ENABLE_DEBUG #ifdef G_ENABLE_DEBUG
#define IF_DEBUG(debug_type) if (_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type) #define IF_DEBUG(debug_type) if (_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type)
@ -525,18 +523,9 @@ g_object_do_get_property (GObject *object,
static void static void
g_object_real_dispose (GObject *object) g_object_real_dispose (GObject *object)
{ {
guint ref_count;
g_signal_handlers_destroy (object); g_signal_handlers_destroy (object);
g_datalist_id_set_data (&object->qdata, quark_closure_array, NULL); g_datalist_id_set_data (&object->qdata, quark_closure_array, NULL);
/* yes, temporarily altering the ref_count is hackish, but that
* enforces people not jerking around with weak_ref notifiers
*/
ref_count = g_atomic_int_get (&object->ref_count);
object->ref_count = 0;
g_datalist_id_set_data (&object->qdata, quark_weak_refs, NULL); g_datalist_id_set_data (&object->qdata, quark_weak_refs, NULL);
object->ref_count = ref_count;
} }
static void static void
@ -587,11 +576,9 @@ g_object_freeze_notify (GObject *object)
if (g_atomic_int_get (&object->ref_count) == 0) if (g_atomic_int_get (&object->ref_count) == 0)
return; return;
g_static_rec_mutex_lock (&notify_mutex);
g_object_ref (object); g_object_ref (object);
g_object_notify_queue_freeze (object, &property_notify_context); g_object_notify_queue_freeze (object, &property_notify_context);
g_object_unref (object); g_object_unref (object);
g_static_rec_mutex_unlock (&notify_mutex);
} }
void void
@ -624,11 +611,9 @@ g_object_notify (GObject *object,
{ {
GObjectNotifyQueue *nqueue; GObjectNotifyQueue *nqueue;
g_static_rec_mutex_lock (&notify_mutex);
nqueue = g_object_notify_queue_freeze (object, &property_notify_context); nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
g_object_notify_queue_add (object, nqueue, pspec); g_object_notify_queue_add (object, nqueue, pspec);
g_object_notify_queue_thaw (object, nqueue); g_object_notify_queue_thaw (object, nqueue);
g_static_rec_mutex_unlock (&notify_mutex);
} }
g_object_unref (object); g_object_unref (object);
} }
@ -643,14 +628,12 @@ g_object_thaw_notify (GObject *object)
return; return;
g_object_ref (object); g_object_ref (object);
g_static_rec_mutex_lock (&notify_mutex);
nqueue = g_object_notify_queue_from_object (object, &property_notify_context); nqueue = g_object_notify_queue_from_object (object, &property_notify_context);
if (!nqueue || !nqueue->freeze_count) if (!nqueue || !nqueue->freeze_count)
g_warning ("%s: property-changed notification for %s(%p) is not frozen", g_warning ("%s: property-changed notification for %s(%p) is not frozen",
G_STRFUNC, G_OBJECT_TYPE_NAME (object), object); G_STRFUNC, G_OBJECT_TYPE_NAME (object), object);
else else
g_object_notify_queue_thaw (object, nqueue); g_object_notify_queue_thaw (object, nqueue);
g_static_rec_mutex_unlock (&notify_mutex);
g_object_unref (object); g_object_unref (object);
} }
@ -706,9 +689,7 @@ object_set_property (GObject *object,
else else
{ {
class->set_property (object, param_id, &tmp_value, pspec); class->set_property (object, param_id, &tmp_value, pspec);
g_static_rec_mutex_lock (&notify_mutex);
g_object_notify_queue_add (object, nqueue, pspec); g_object_notify_queue_add (object, nqueue, pspec);
g_static_rec_mutex_unlock (&notify_mutex);
} }
g_value_unset (&tmp_value); g_value_unset (&tmp_value);
} }
@ -1063,7 +1044,6 @@ g_object_set_valist (GObject *object,
g_return_if_fail (G_IS_OBJECT (object)); g_return_if_fail (G_IS_OBJECT (object));
g_static_rec_mutex_lock (&notify_mutex);
g_object_ref (object); g_object_ref (object);
nqueue = g_object_notify_queue_freeze (object, &property_notify_context); nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
@ -1120,7 +1100,6 @@ g_object_set_valist (GObject *object,
g_object_notify_queue_thaw (object, nqueue); g_object_notify_queue_thaw (object, nqueue);
g_object_unref (object); g_object_unref (object);
g_static_rec_mutex_unlock (&notify_mutex);
} }
void void
@ -1226,7 +1205,6 @@ g_object_set_property (GObject *object,
g_return_if_fail (property_name != NULL); g_return_if_fail (property_name != NULL);
g_return_if_fail (G_IS_VALUE (value)); g_return_if_fail (G_IS_VALUE (value));
g_static_rec_mutex_lock (&notify_mutex);
g_object_ref (object); g_object_ref (object);
nqueue = g_object_notify_queue_freeze (object, &property_notify_context); nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
@ -1252,7 +1230,6 @@ g_object_set_property (GObject *object,
g_object_notify_queue_thaw (object, nqueue); g_object_notify_queue_thaw (object, nqueue);
g_object_unref (object); g_object_unref (object);
g_static_rec_mutex_unlock (&notify_mutex);
} }
void void
@ -1668,9 +1645,9 @@ void
g_object_unref (gpointer _object) g_object_unref (gpointer _object)
{ {
GObject *object = _object; GObject *object = _object;
gint old_val; gint old_ref;
gboolean is_zero; gboolean is_zero;
g_return_if_fail (G_IS_OBJECT (object)); g_return_if_fail (G_IS_OBJECT (object));
g_return_if_fail (object->ref_count > 0); g_return_if_fail (object->ref_count > 0);
@ -1679,44 +1656,46 @@ g_object_unref (gpointer _object)
G_BREAKPOINT (); G_BREAKPOINT ();
#endif /* G_ENABLE_DEBUG */ #endif /* G_ENABLE_DEBUG */
retry1: /* here we want to atomically do: if (ref_count>1) { ref_count--; return; } */
old_val = g_atomic_int_get (&object->ref_count); retry_atomic_decrement1:
if (old_val > 1) old_ref = g_atomic_int_get (&object->ref_count);
if (old_ref > 1)
{ {
if (!g_atomic_int_compare_and_exchange (&object->ref_count, old_val, old_val-1)) if (!g_atomic_int_compare_and_exchange (&object->ref_count, old_ref, old_ref - 1))
goto retry1; goto retry_atomic_decrement1;
/* if we went from 2->1 we need to notify toggle refs if any */ /* if we went from 2->1 we need to notify toggle refs if any */
if (old_val == 2 && OBJECT_HAS_TOGGLE_REF (object)) if (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object))
toggle_refs_notify (object, TRUE); toggle_refs_notify (object, TRUE);
} }
else else
{ {
/* removing the last ref */ /* we are about tp remove the last reference */
G_OBJECT_GET_CLASS (object)->dispose (object); G_OBJECT_GET_CLASS (object)->dispose (object);
/* dispose could have resurected the object */ /* may have been re-referenced meanwhile */
retry2: retry_atomic_decrement2:
old_val = g_atomic_int_get (&object->ref_count); old_ref = g_atomic_int_get (&object->ref_count);
if (old_val > 1) if (old_ref > 1)
{ {
if (!g_atomic_int_compare_and_exchange (&object->ref_count, old_val, old_val-1)) if (!g_atomic_int_compare_and_exchange (&object->ref_count, old_ref, old_ref - 1))
goto retry2; goto retry_atomic_decrement2;
/* if we went from 2->1 we need to notify toggle refs if any */ /* if we went from 2->1 we need to notify toggle refs if any */
if (old_val == 2 && OBJECT_HAS_TOGGLE_REF (object)) if (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object))
toggle_refs_notify (object, TRUE); toggle_refs_notify (object, TRUE);
return; return;
} }
/* we are still taking away the last ref */ /* we are still in the process of taking away the last ref */
g_datalist_id_set_data (&object->qdata, quark_closure_array, NULL);
g_signal_handlers_destroy (object); g_signal_handlers_destroy (object);
g_datalist_id_set_data (&object->qdata, quark_weak_refs, NULL); g_datalist_id_set_data (&object->qdata, quark_weak_refs, NULL);
/* now we really take away the last ref */ /* decrement the last reference */
is_zero = g_atomic_int_dec_and_test (&object->ref_count); is_zero = g_atomic_int_dec_and_test (&object->ref_count);
/* may have been re-referenced meanwhile */ /* may have been re-referenced meanwhile */
if (G_LIKELY (is_zero)) if (G_LIKELY (is_zero))
{ {

View File

@ -198,9 +198,7 @@ g_param_spec_sink (GParamSpec *pspec)
g_return_if_fail (pspec->ref_count > 0); g_return_if_fail (pspec->ref_count > 0);
if (g_datalist_id_remove_no_notify (&pspec->qdata, quark_floating)) if (g_datalist_id_remove_no_notify (&pspec->qdata, quark_floating))
{ g_param_spec_unref (pspec);
g_param_spec_unref (pspec);
}
} }
G_CONST_RETURN gchar* G_CONST_RETURN gchar*

View File

@ -222,9 +222,9 @@ struct _Handler
Handler *next; Handler *next;
Handler *prev; Handler *prev;
GQuark detail; GQuark detail;
guint ref_count; /* ABI change, was 16 bits but since it's internal... */ guint ref_count;
guint block_count : 12; guint block_count : 16;
#define HANDLER_MAX_BLOCK_COUNT (1 << 12) #define HANDLER_MAX_BLOCK_COUNT (1 << 16)
guint after : 1; guint after : 1;
GClosure *closure; GClosure *closure;
}; };
@ -454,17 +454,6 @@ handler_match_free1_R (HandlerMatch *node,
return next; return next;
} }
/* copy of gclosure.c code here to make the first 32 bits of the closure
* atomic. */
typedef union
{
GClosure bits;
gint atomic;
} GAtomicClosureBits;
#define BITS_AS_INT(b) (((GAtomicClosureBits*)(b))->atomic)
#define CLOSURE_READ_BITS(cl,bits) (BITS_AS_INT(bits) = g_atomic_int_get ((gint*)(cl)))
static HandlerMatch* static HandlerMatch*
handlers_find (gpointer instance, handlers_find (gpointer instance,
GSignalMatchType mask, GSignalMatchType mask,
@ -491,26 +480,20 @@ handlers_find (gpointer instance,
} }
mask = ~mask; mask = ~mask;
for (handler = hlist ? hlist->handlers : NULL; handler; handler = handler->next) for (handler = hlist ? hlist->handlers : NULL; handler; handler = handler->next)
{ if (handler->sequential_number &&
GClosure bits; ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) &&
((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) &&
CLOSURE_READ_BITS (handler->closure, &bits); ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) &&
((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) &&
if (handler->sequential_number && ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller &&
((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) && handler->closure->meta_marshal == 0 &&
((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) && ((GCClosure*) handler->closure)->callback == func)))
((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) && {
((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) && mlist = handler_match_prepend (mlist, handler, signal_id);
((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller && if (one_and_only)
bits.meta_marshal == 0 && return mlist;
((GCClosure*) handler->closure)->callback == func))) }
{
mlist = handler_match_prepend (mlist, handler, signal_id);
if (one_and_only)
return mlist;
}
}
} }
else else
{ {
@ -535,25 +518,19 @@ handlers_find (gpointer instance,
} }
for (handler = hlist->handlers; handler; handler = handler->next) for (handler = hlist->handlers; handler; handler = handler->next)
{ if (handler->sequential_number &&
GClosure bits; ((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) &&
((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) &&
CLOSURE_READ_BITS (handler->closure, &bits); ((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) &&
((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) &&
if (handler->sequential_number && ((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller &&
((mask & G_SIGNAL_MATCH_DETAIL) || handler->detail == detail) && handler->closure->meta_marshal == 0 &&
((mask & G_SIGNAL_MATCH_CLOSURE) || handler->closure == closure) && ((GCClosure*) handler->closure)->callback == func)))
((mask & G_SIGNAL_MATCH_DATA) || handler->closure->data == data) && {
((mask & G_SIGNAL_MATCH_UNBLOCKED) || handler->block_count == 0) && mlist = handler_match_prepend (mlist, handler, hlist->signal_id);
((mask & G_SIGNAL_MATCH_FUNC) || (handler->closure->marshal == node->c_marshaller && if (one_and_only)
bits.meta_marshal == 0 && return mlist;
((GCClosure*) handler->closure)->callback == func))) }
{
mlist = handler_match_prepend (mlist, handler, hlist->signal_id);
if (one_and_only)
return mlist;
}
}
} }
} }
} }