eina: actually check the pid only if we fail with main loop check.

NOTE: If we are out of luck this test can work after a fork, but most
of the time it will be correct and cost nothing, instead of costing
a syscall.


SVN revision: 71988
This commit is contained in:
Cedric BAIL 2012-06-12 07:58:11 +00:00
parent 8ece74f1fd
commit 491e44bb5f
1 changed files with 13 additions and 8 deletions

View File

@ -410,8 +410,17 @@ EAPI Eina_Bool
eina_main_loop_is(void)
{
#ifdef EFL_HAVE_THREADS
pid_t pid = getpid();
pid_t pid;
# ifdef _WIN32
if (_eina_main_loop == GetCurrentThreadId())
return EINA_TRUE;
# else
if (pthread_equal(_eina_main_loop, pthread_self()))
return EINA_TRUE;
# endif
pid = getpid();
# ifdef _WIN32
if (pid != _eina_pid)
{
@ -419,9 +428,7 @@ eina_main_loop_is(void)
_eina_main_loop = GetCurrentThreadId();
return EINA_TRUE;
}
if (_eina_main_loop == GetCurrentThreadId())
return EINA_TRUE;
# else
#else
if (pid != _eina_pid)
{
/* This is in case of a fork, but don't like the solution */
@ -429,11 +436,9 @@ eina_main_loop_is(void)
_eina_main_loop = pthread_self();
return EINA_TRUE;
}
if (pthread_equal(_eina_main_loop, pthread_self()))
return EINA_TRUE;
# endif
#endif
#endif
return EINA_FALSE;
}