gobject: set flags without atomic during constructions

We are still very early. Initialize the flags without
an atomic.

Note that we also:

- above initialize object->ref_count without atomic.

- we called atomic operation set_object_in_construction(),
  which sets certain flags, but relies on the other
  flags being initialized correctly (they are not touched
  by g_atomic_int_or()). Those other flags are also initialized
  without atomic, relying on being memset() to zero.
This commit is contained in:
Thomas Haller 2025-02-28 10:29:15 +01:00
parent c5a6a21071
commit 0d596bab12

View File

@ -1793,12 +1793,6 @@ object_in_construction (GObject *object)
return (object_get_optional_flags (object) & OPTIONAL_FLAG_IN_CONSTRUCTION) != 0;
}
static inline void
set_object_in_construction (GObject *object)
{
object_set_optional_flags (object, OPTIONAL_FLAG_IN_CONSTRUCTION);
}
static inline void
unset_object_in_construction (GObject *object)
{
@ -1809,18 +1803,22 @@ static void
g_object_init (GObject *object,
GObjectClass *class)
{
guint *p_flags;
object->ref_count = 1;
object->qdata = NULL;
/* We are still very early during construction. At this point we set the flag
* without atomic. */
p_flags = object_get_optional_flags_p (object);
*p_flags = OPTIONAL_FLAG_IN_CONSTRUCTION;
if (CLASS_HAS_PROPS (class) && CLASS_NEEDS_NOTIFY (class))
{
/* freeze object's notification queue, g_object_new_internal() preserves pairedness */
g_object_notify_queue_freeze (object, TRUE);
}
/* mark object in-construction for notify_queue_thaw() and to allow construct-only properties */
set_object_in_construction (object);
GOBJECT_IF_DEBUG (OBJECTS,
{
G_LOCK (debug_objects);