diff --git a/legacy/evas/src/lib/canvas/evas_main.c b/legacy/evas/src/lib/canvas/evas_main.c index 5b023e5f38..32fd34fa01 100644 --- a/legacy/evas/src/lib/canvas/evas_main.c +++ b/legacy/evas/src/lib/canvas/evas_main.c @@ -2,6 +2,11 @@ #include "evas_private.h" #include "evas_cs.h" +#ifdef LKDEBUG +EAPI Eina_Bool lockdebug = EINA_FALSE; +EAPI int lockmax = 0; +#endif + static int _evas_init_count = 0; int _evas_log_dom_global = -1; /** @@ -22,6 +27,14 @@ evas_init(void) if (++_evas_init_count != 1) return _evas_init_count; +#ifdef LKDEBUG + if (getenv("EVAS_LOCK_DEBUG")) + { + lockdebug = EINA_TRUE; + lockmax = atoi(getenv("EVAS_LOCK_DEBUG")); + } +#endif + #ifdef HAVE_EVIL if (!evil_init()) return --_evas_init_count; diff --git a/legacy/evas/src/lib/include/evas_common.h b/legacy/evas/src/lib/include/evas_common.h index 93d321ca0e..6889c06387 100644 --- a/legacy/evas/src/lib/include/evas_common.h +++ b/legacy/evas/src/lib/include/evas_common.h @@ -135,19 +135,50 @@ extern EAPI int _evas_log_dom_global; # include #endif +//#define LKDEBUG 1 + +#ifdef LKDEBUG +EAPI Eina_Bool lockdebug; +EAPI int lockmax; +#endif + #define LK(x) pthread_mutex_t x #ifndef EVAS_FRAME_QUEUING -# define LKI(x) pthread_mutex_init(&(x), NULL); +# define LKI(x) pthread_mutex_init(&(x), NULL) #else -# define LKI(x) {pthread_mutexattr_t attr;\ - pthread_mutexattr_init(&attr); \ - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \ - pthread_mutex_init(&(x), &attr);} +# define LKI(x) do {pthread_mutexattr_t __attr;\ + pthread_mutexattr_init(&__attr); \ + pthread_mutexattr_settype(&__attr, PTHREAD_MUTEX_RECURSIVE); \ + pthread_mutex_init(&(x), &__attr);} while (0) #endif -# define LKD(x) pthread_mutex_destroy(&(x)); -# define LKL(x) pthread_mutex_lock(&(x)); -# define LKT(x) pthread_mutex_trylock(&(x)); -# define LKU(x) pthread_mutex_unlock(&(x)); +# define LKD(x) pthread_mutex_destroy(&(x)) +# ifdef LKDEBUG +# define LKL(x) \ + do { \ + if (lockdebug) { \ + struct timeval t0, t1; \ + int dt; \ + gettimeofday(&t0, NULL); \ + pthread_mutex_lock(&(x)); \ + gettimeofday(&t1, NULL); \ + dt = (t1.tv_sec - t0.tv_sec) * 1000000; \ + if (t1.tv_usec > t0.tv_usec) dt += (t1.tv_usec - t0.tv_usec); \ + else dt -= t0.tv_usec - t1.tv_usec; \ + dt /= 1000; \ + if (dt > lockmax) { \ + fprintf(stderr, "HANG %ims - %s:%i - %s()\n", \ + dt, __FILE__, __LINE__, __FUNCTION__); \ + } \ + } \ + else { \ + pthread_mutex_lock(&(x)); \ + } \ + } while (0) +# else +# define LKL(x) pthread_mutex_lock(&(x)) +# endif +# define LKT(x) pthread_mutex_trylock(&(x)) +# define LKU(x) pthread_mutex_unlock(&(x)) # define TH(x) pthread_t x # define THI(x) int x # define TH_MAX 8