discomfitor pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=1332e0e0259e6291f34c2eaf317aa9452d19e316
commit 1332e0e0259e6291f34c2eaf317aa9452d19e316 Author: Mike Blumenkrantz <zm...@samsung.com> Date: Fri Jun 29 11:31:10 2018 -0400 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 023a9ca2ee32529849e770f057f58592956dee47 Reviewers: bu5hm4n, devilhorns Reviewed By: bu5hm4n Subscribers: cedric, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D6472 --- src/lib/eo/eo.c | 10 ++++++---- src/lib/eo/eo_private.h | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c index f2ee051c7e..3fb7fd6639 100644 --- a/src/lib/eo/eo.c +++ b/src/lib/eo/eo.c @@ -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) { diff --git a/src/lib/eo/eo_private.h b/src/lib/eo/eo_private.h index 5f62f084e4..e42078a1fd 100644 --- a/src/lib/eo/eo_private.h +++ b/src/lib/eo/eo_private.h @@ -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 */ --