Eo class creation: Simplify code using recursive locks.

Now that we have recursive locks, the class creation code can be much simpler.
All the code there was essentially our own implementation of recursive locks,
or rather a special case of those.

This is no longer needed.
This commit is contained in:
Tom Hacohen 2016-09-08 11:14:32 +01:00
parent 150cc62a0d
commit 6b60560773
2 changed files with 12 additions and 26 deletions

View File

@ -128,7 +128,7 @@ typedef Eo Efl_Object;
* Don't touch it if you don't know what you are doing.
* @internal
*/
EAPI extern Eina_Spinlock _efl_class_creation_lock;
EAPI extern Eina_Lock _efl_class_creation_lock;
/**
* @var _efl_object_init_generation
@ -320,39 +320,25 @@ const Efl_Class * \
class_get_func_name(void) \
{ \
const Efl_Class *_tmp_parent_class; \
static volatile unsigned char lk_init = 0; \
static Eina_Spinlock _my_lock; \
static const Efl_Class * volatile _my_class = NULL; \
static unsigned int _my_init_generation = 1; \
if (EINA_UNLIKELY(_efl_object_init_generation != _my_init_generation)) \
{ \
_my_class = NULL; /* It's freed in efl_object_shutdown(). */ \
lk_init = 0; \
} \
if (EINA_LIKELY(!!_my_class)) return _my_class; \
\
eina_spinlock_take(&_efl_class_creation_lock); \
if (!lk_init) \
eina_spinlock_new(&_my_lock); \
if (lk_init < 2) eina_spinlock_take(&_my_lock); \
if (!lk_init) \
lk_init = 1; \
else \
eina_lock_take(&_efl_class_creation_lock); \
if (!!_my_class) \
{ \
if (lk_init < 2) eina_spinlock_release(&_my_lock); \
eina_spinlock_release(&_efl_class_creation_lock); \
eina_lock_release(&_efl_class_creation_lock); \
return _my_class; \
} \
eina_spinlock_release(&_efl_class_creation_lock); \
_tmp_parent_class = parent_class; \
_my_class = efl_class_new(class_desc, _tmp_parent_class, __VA_ARGS__); \
_my_init_generation = _efl_object_init_generation; \
eina_spinlock_release(&_my_lock); \
eina_lock_release(&_efl_class_creation_lock); \
\
eina_spinlock_take(&_efl_class_creation_lock); \
eina_spinlock_free(&_my_lock); \
lk_init = 2; \
eina_spinlock_release(&_efl_class_creation_lock); \
return _my_class; \
}

View File

@ -19,7 +19,7 @@
#define EFL_OBJECT_OP_IDS_FIRST 1
/* Used inside the class_get functions of classes, see #EFL_DEFINE_CLASS */
EAPI Eina_Spinlock _efl_class_creation_lock;
EAPI Eina_Lock _efl_class_creation_lock;
EAPI unsigned int _efl_object_init_generation = 1;
int _eo_log_dom = -1;
@ -1342,11 +1342,11 @@ efl_class_new(const Efl_Class_Description *desc, const Efl_Class *parent_id, ...
{
Eo_Id new_id;
eina_spinlock_take(&_efl_class_creation_lock);
eina_lock_take(&_efl_class_creation_lock);
new_id = (_eo_classes_last_id + 1) | MASK_CLASS_TAG;
_eo_classes_expand();
_eo_classes[_UNMASK_ID(new_id) - 1] = klass;
eina_spinlock_release(&_efl_class_creation_lock);
eina_lock_release(&_efl_class_creation_lock);
klass->header.id = new_id;
}
@ -1837,7 +1837,7 @@ efl_object_init(void)
return EINA_FALSE;
}
if (!eina_spinlock_new(&_efl_class_creation_lock))
if (!eina_lock_recursive_new(&_efl_class_creation_lock))
{
EINA_LOG_ERR("Could not init lock.");
return EINA_FALSE;
@ -1927,15 +1927,15 @@ efl_object_shutdown(void)
eo_class_free(*cls_itr);
}
eina_spinlock_take(&_efl_class_creation_lock);
eina_lock_take(&_efl_class_creation_lock);
_eo_classes_release();
eina_spinlock_release(&_efl_class_creation_lock);
eina_lock_release(&_efl_class_creation_lock);
eina_hash_free(_ops_storage);
eina_spinlock_free(&_super_class_lock);
eina_spinlock_free(&_ops_storage_lock);
eina_spinlock_free(&_efl_class_creation_lock);
eina_lock_free(&_efl_class_creation_lock);
_eo_free_ids_tables(_eo_table_data_get());
eina_tls_free(_eo_table_data);