From cb44d8974fd0f8963b57e1c1115e4870e53cb81e Mon Sep 17 00:00:00 2001 From: cedric Date: Tue, 9 Aug 2011 08:47:57 +0000 Subject: [PATCH] eina: detect main loop for windows to. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@62239 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/eina_main.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/lib/eina_main.c b/src/lib/eina_main.c index c7ed73c..976f08f 100644 --- a/src/lib/eina_main.c +++ b/src/lib/eina_main.c @@ -28,6 +28,13 @@ # undef WIN32_LEAN_AND_MEAN #endif +#ifdef EFL_HAVE_THREADS +# if !(defined(_WIN32_WCE)) && !(defined(_WIN32)) +# include +# include +# endif +#endif + #include "eina_lock.h" #include "eina_config.h" #include "eina_private.h" @@ -76,13 +83,14 @@ static int _eina_log_dom = -1; EAPI Eina_Bool _eina_threads_activated = EINA_FALSE; -#ifdef EINA_HAVE_THREADS +#ifdef EFL_HAVE_THREADS # ifdef _WIN32_WCE -# warning "no way to know the main loop thread id yet on Windows CE !" +EAPI HANDLE _eina_main_loop; # elif defined(_WIN32) -# warning "no way to know the main loop thread id yet on Windows !" +EAPI HANDLE _eina_main_loop; # else -EAPI pthread_t _eina_main_loop;; +EAPI pthread_t _eina_main_loop; +static pid_t _eina_pid; # endif #endif @@ -214,9 +222,14 @@ eina_init(void) return 0; } -#ifdef EINA_HAVE_THREADS -# if !(defined(_WIN32_WCE)) && !(defined(_WIN32)) +#ifdef EFL_HAVE_THREADS +# ifdef _WIN32_CE + _eina_main_loop = (HANDLE) GetCurrentThreadId(); +# elif defined (_WIN32) + _eina_main_loop = (HANDLE) GetCurrentThreadId(); +# else _eina_main_loop = pthread_self(); + _eina_pid = getpid(); # endif #endif @@ -333,13 +346,27 @@ eina_threads_shutdown(void) EAPI Eina_Bool eina_main_loop_is(void) { -#ifdef EINA_HAVE_THREADS +#ifdef EFL_HAVE_THREADS /* FIXME: need to check how to do this on windows */ # ifdef _WIN32_CE + if (_eina_main_loop == (HANDLE) GetCurrentThreadId()) + return EINA_TRUE; return EINA_FALSE; # elif defined(_WIN32) + if (_eina_main_loop == (HANDLE) GetCurrentThreadId()) + return EINA_TRUE; return EINA_FALSE; # else + pid_t pid = getpid(); + + if (pid != _eina_pid) + { + /* This is in case of a fork, but don't like the solution */ + _eina_pid = pid; + _eina_main_loop = pthread_self(); + return EINA_TRUE; + } + if (pthread_equal(_eina_main_loop, pthread_self())) return EINA_TRUE; # endif -- 2.7.4