eo: improve thread check during class construction

Summary:
a common use case is for a class to be constructed during a thread+mainloop
sync (e.g., ecore_thread_main_loop_begin() ecore_thread_main_loop_end())
and then naturally destroyed in the main thread during shutdown

ref 023a9ca2ee

Reviewers: bu5hm4n, devilhorns

Reviewed By: bu5hm4n

Subscribers: cedric, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D6472
This commit is contained in:
Mike Blumenkrantz 2018-06-29 11:31:10 -04:00
parent cf23ec291d
commit 1332e0e025
2 changed files with 8 additions and 4 deletions

View File

@ -1298,8 +1298,7 @@ _eo_class_constructor(_Efl_Class *klass)
{
klass->constructed = EINA_TRUE;
if (eina_thread_self() != _efl_object_main_thread)
CRI("Calling class constructor from non-main thread! This will crash later!");
klass->construction_thread = eina_thread_self();
if (klass->desc->class_constructor)
klass->desc->class_constructor(_eo_class_id_get(klass));
@ -1309,9 +1308,12 @@ static void
eo_class_free(_Efl_Class *klass)
{
void *data;
Eina_Thread self = eina_thread_self();
if (eina_thread_self() != _efl_object_main_thread)
CRI("Calling class deconstructor from non-main thread! This will crash!");
if ((self != _efl_object_main_thread) &&
(self != klass->construction_thread))
CRI("Calling class deconstructor from thread that did not call constructor and is not main thread!\n"
"This will probably crash!");
if (klass->constructed)
{

View File

@ -203,6 +203,8 @@ struct _Efl_Class
unsigned int data_offset; /* < Offset of the data within object data. */
unsigned int ops_count; /* < Offset of the data within object data. */
Eina_Thread construction_thread; /** < the thread which called the class constructor */
Eina_Bool constructed : 1;
Eina_Bool functions_set : 1;
/* [extensions*] + NULL */