2363
2363
g_type_class_ref (GType type)
2365
2365
TypeNode *node;
2367
/* optimize for common code path
2368
/* optimize for common code path */
2369
2369
G_WRITE_LOCK (&type_rw_lock);
2370
2370
node = lookup_type_node_I (type);
2371
2371
if (node && node->is_classed && node->data &&
2372
node->data->class.class && node->data->common.ref_count > 0)
2372
node->data->class.class &&
2373
node->data->class.init_state == INITIALIZED)
2374
2375
type_data_ref_Wm (node);
2375
2376
G_WRITE_UNLOCK (&type_rw_lock);
2377
2377
return node->data->class.class;
2380
2379
if (!node || !node->is_classed ||
2381
2380
(node->data && node->data->common.ref_count < 1))
2385
2384
type_descriptive_name_I (type));
2389
2387
type_data_ref_Wm (node);
2388
ptype = NODE_PARENT_TYPE (node);
2389
G_WRITE_UNLOCK (&type_rw_lock);
2391
g_static_rec_mutex_lock (&class_init_rec_mutex); /* required locking order: 1) class_init_rec_mutex, 2) type_rw_lock */
2392
/* here, we either have node->data->class.class == NULL, or a recursive
2393
* call to g_type_class_ref() with a partly initialized class, or
2394
* node->data->class.init_state == INITIALIZED, because any
2395
* concurrently running initialization was guarded by class_init_rec_mutex.
2391
2397
if (!node->data->class.class) /* class uninitialized */
2393
GType ptype = NODE_PARENT_TYPE (node);
2394
GTypeClass *pclass = NULL;
2395
G_WRITE_UNLOCK (&type_rw_lock);
2396
g_static_rec_mutex_lock (&class_init_rec_mutex); /* required locking order: 1) class_init_rec_mutex, 2) type_rw_lock */
2399
pclass = g_type_class_ref (ptype);
2400
G_WRITE_LOCK (&type_rw_lock);
2401
node = lookup_type_node_I (type);
2402
if (node->data->class.class)
2403
INVALID_RECURSION ("g_type_plugin_*", node->plugin, NODE_NAME (node));
2407
G_WRITE_LOCK (&type_rw_lock);
2408
node = lookup_type_node_I (type);
2410
if (!node->data->class.class) /* class could have been initialized meanwhile */
2411
type_class_init_Wm (node, pclass);
2412
G_WRITE_UNLOCK (&type_rw_lock);
2413
g_static_rec_mutex_unlock (&class_init_rec_mutex);
2399
/* acquire reference on parent class */
2400
GTypeClass *pclass = ptype ? g_type_class_ref (ptype) : NULL;
2401
G_WRITE_LOCK (&type_rw_lock);
2402
if (node->data->class.class) /* class was initialized during parent class initialization? */
2403
INVALID_RECURSION ("g_type_plugin_*", node->plugin, NODE_NAME (node));
2404
type_class_init_Wm (node, pclass);
2405
G_WRITE_UNLOCK (&type_rw_lock);
2407
g_static_rec_mutex_unlock (&class_init_rec_mutex);
2415
2409
return node->data->class.class;