X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Flib%2Feina_main.c;h=fb2bb0df73e658e44da038e71b048ba6ff89a60b;hb=1261f21c8ea6796812d63e170409d21e78d01860;hp=976f08f445695a4d42d2f46642761847ed82ce91;hpb=d33c43866356caa7b90ea8853595b6370641995d;p=profile%2Fivi%2Feina.git diff --git a/src/lib/eina_main.c b/src/lib/eina_main.c index 976f08f..fb2bb0d 100644 --- a/src/lib/eina_main.c +++ b/src/lib/eina_main.c @@ -29,12 +29,24 @@ #endif #ifdef EFL_HAVE_THREADS -# if !(defined(_WIN32_WCE)) && !(defined(_WIN32)) +# ifdef HAVE_SYS_TYPES_H # include +# endif +# ifdef HAVE_UNISTD_H # include # endif #endif +#ifdef HAVE_MCHECK_H +# ifdef HAVE_MTRACE +# define MT 1 +# endif +#endif + +#ifdef MT +#include +#endif + #include "eina_lock.h" #include "eina_config.h" #include "eina_private.h" @@ -54,6 +66,12 @@ #include "eina_magic.h" #include "eina_rectangle.h" #include "eina_safety_checks.h" +#include "eina_inlist.h" +#include "eina_inarray.h" +#include "eina_value.h" +/* no model for now +#include "eina_model.h" + */ /*============================================================================* * Local * @@ -82,22 +100,29 @@ static int _eina_log_dom = -1; #define DBG(...) EINA_LOG_DOM_DBG(_eina_log_dom, __VA_ARGS__) EAPI Eina_Bool _eina_threads_activated = EINA_FALSE; +EAPI Eina_Error EINA_ERROR_NOT_MAIN_LOOP = 0; + +static const char EINA_ERROR_NOT_MAIN_LOOP_STR[] = "Main loop thread check failed."; #ifdef EFL_HAVE_THREADS -# ifdef _WIN32_WCE -EAPI HANDLE _eina_main_loop; -# elif defined(_WIN32) -EAPI HANDLE _eina_main_loop; +# ifdef _WIN32 +EAPI DWORD _eina_main_loop; # else EAPI pthread_t _eina_main_loop; -static pid_t _eina_pid; # endif +static pid_t _eina_pid; #endif -#ifdef EINA_HAVE_DEBUG_THREADS +#ifdef MT +static int _mt_enabled = 0; +#endif + +#ifdef EFL_HAVE_THREADS EAPI int _eina_threads_debug = 0; +# if !defined(_WIN32_WCE) && !defined(_WIN32) EAPI pthread_mutex_t _eina_tracking_lock; EAPI Eina_Inlist *_eina_tracking = NULL; +# endif #endif /* place module init/shutdown functions here to avoid other modules @@ -111,6 +136,7 @@ EAPI Eina_Inlist *_eina_tracking = NULL; S(magic_string); S(iterator); S(accessor); + S(inarray); S(array); S(module); S(mempool); @@ -128,6 +154,13 @@ EAPI Eina_Inlist *_eina_tracking = NULL; S(quadtree); S(simple_xml); S(file); + S(prefix); + S(value); + S(tmpstr); + S(thread); +/* no model for now + S(model); + */ #undef S struct eina_desc_setup @@ -140,17 +173,18 @@ struct eina_desc_setup static const struct eina_desc_setup _eina_desc_setup[] = { #define S(x) {# x, eina_ ## x ## _init, eina_ ## x ## _shutdown} /* log is a special case as it needs printf */ + S(stringshare), S(error), S(safety_checks), S(magic_string), S(iterator), S(accessor), + S(inarray), S(array), S(module), S(mempool), S(list), S(binshare), - S(stringshare), S(ustringshare), S(matrixsparse), S(convert), @@ -161,7 +195,14 @@ static const struct eina_desc_setup _eina_desc_setup[] = { S(ustrbuf), S(quadtree), S(simple_xml), - S(file) + S(file), + S(prefix), + S(value), + S(tmpstr), + S(thread) +/* no model for now + S(model) + */ #undef S }; static const size_t _eina_desc_setup_len = sizeof(_eina_desc_setup) / @@ -208,6 +249,14 @@ eina_init(void) if (EINA_LIKELY(_eina_main_count > 0)) return ++_eina_main_count; +#ifdef MT + if ((getenv("EINA_MTRACE")) && (getenv("MALLOC_TRACE"))) + { + _mt_enabled = 1; + mtrace(); + } +#endif + if (!eina_log_init()) { fprintf(stderr, "Could not initialize eina logging system.\n"); @@ -222,15 +271,16 @@ eina_init(void) return 0; } + EINA_ERROR_NOT_MAIN_LOOP = eina_error_msg_static_register( + EINA_ERROR_NOT_MAIN_LOOP_STR); + #ifdef EFL_HAVE_THREADS -# ifdef _WIN32_CE - _eina_main_loop = (HANDLE) GetCurrentThreadId(); -# elif defined (_WIN32) - _eina_main_loop = (HANDLE) GetCurrentThreadId(); +# ifdef _WIN32 + _eina_main_loop = GetCurrentThreadId(); # else _eina_main_loop = pthread_self(); - _eina_pid = getpid(); # endif + _eina_pid = getpid(); #endif #ifdef EINA_HAVE_DEBUG_THREADS @@ -252,6 +302,8 @@ eina_init(void) } } + eina_cpu_count_internal(); + _eina_main_count = 1; return 1; } @@ -259,6 +311,11 @@ eina_init(void) EAPI int eina_shutdown(void) { + if (_eina_main_count <= 0) + { + ERR("Init count not greater than 0 in shutdown."); + return 0; + } _eina_main_count--; if (EINA_UNLIKELY(_eina_main_count == 0)) { @@ -267,6 +324,13 @@ eina_shutdown(void) #ifdef EINA_HAVE_DEBUG_THREADS pthread_mutex_destroy(&_eina_tracking_lock); #endif +#ifdef MT + if (_mt_enabled) + { + muntrace(); + _mt_enabled = 0; + } +#endif } return _eina_main_count; @@ -325,7 +389,10 @@ eina_threads_shutdown(void) fprintf(stderr, "* LOCK STILL TAKEN : *\n"); fprintf(stderr, "*************************\n"); EINA_INLIST_FOREACH(_eina_tracking, lk) - eina_lock_debug(lk); + { + fprintf(stderr, "=======\n"); + eina_lock_debug(lk); + } fprintf(stderr, "*************************\n"); abort(); } @@ -347,18 +414,25 @@ EAPI Eina_Bool eina_main_loop_is(void) { #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()) + pid_t pid; + +# ifdef _WIN32 + if (_eina_main_loop == GetCurrentThreadId()) return EINA_TRUE; - return EINA_FALSE; # else - pid_t pid = getpid(); + if (pthread_equal(_eina_main_loop, pthread_self())) + return EINA_TRUE; +# endif + pid = getpid(); +# ifdef _WIN32 + if (pid != _eina_pid) + { + _eina_pid = pid; + _eina_main_loop = GetCurrentThreadId(); + return EINA_TRUE; + } +#else if (pid != _eina_pid) { /* This is in case of a fork, but don't like the solution */ @@ -366,12 +440,24 @@ eina_main_loop_is(void) _eina_main_loop = pthread_self(); return EINA_TRUE; } +#endif +#endif - if (pthread_equal(_eina_main_loop, pthread_self())) - return EINA_TRUE; + return EINA_FALSE; +} + +/** The purpose of this API should not be documented, it is used only by the one who know what they are doing. */ +EAPI void +eina_main_loop_define(void) +{ +#ifdef EFL_HAVE_THREADS + _eina_pid = getpid(); +# ifdef _WIN32 + _eina_main_loop = GetCurrentThreadId(); +# else + _eina_main_loop = pthread_self(); # endif #endif - return EINA_FALSE; } /**