From c75fe8f5d04a8a5a7835177dbe96bbe31be6c1b8 Mon Sep 17 00:00:00 2001 From: barbieri Date: Fri, 23 Jan 2009 20:36:04 +0000 Subject: [PATCH] evas preload: keep the preload thread alive. before, when no more images were to be preloaded asynchronously, the thread exited, but were not collected. This leads to a huge leak if the process is doing aggressive use of image preloading (ie: photo wall). collecting dead threads in a proper way (read: without race conditions) is a bit harder than keeping just one thread alive, forever. As we do that for evas_pipe (the renderer), let's do the same with preload and save code. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@38746 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/cache/evas_cache_image.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/lib/cache/evas_cache_image.c b/src/lib/cache/evas_cache_image.c index afc8113..89aabfa 100644 --- a/src/lib/cache/evas_cache_image.c +++ b/src/lib/cache/evas_cache_image.c @@ -32,10 +32,12 @@ struct _Evas_Cache_Preload static Eina_Inlist *preload = NULL; static Image_Entry *current = NULL; -static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +static pthread_cond_t cond_done = PTHREAD_COND_INITIALIZER; +static pthread_cond_t cond_new = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t mutex_new = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mutex_surface_alloc = PTHREAD_MUTEX_INITIALIZER; -static pthread_t tid; +static pthread_t tid = 0; static Evas_Bool running = 0; @@ -347,8 +349,16 @@ _evas_cache_image_entry_preload_add(Image_Entry *ie, if (!running) { - if (pthread_create(&tid, NULL, _evas_cache_background_load, NULL) == 0) - running = 1; + if (tid) + { + running = 1; + pthread_cond_signal(&cond_new); + } + else + { + if (pthread_create(&tid, NULL, _evas_cache_background_load, NULL) == 0) + running = 1; + } } ret = 2; @@ -376,7 +386,7 @@ _evas_cache_image_entry_preload_remove(Image_Entry *ie, const void *target) if (current == ie) { /* Wait until ie is processed. */ - pthread_cond_wait(&cond, &mutex); + pthread_cond_wait(&cond_done, &mutex); } else { @@ -1228,7 +1238,7 @@ _evas_cache_background_load(void *data) current = NULL; } - pthread_cond_signal(&cond); + pthread_cond_signal(&cond_done); } pthread_mutex_lock(&mutex); @@ -1241,6 +1251,11 @@ _evas_cache_background_load(void *data) running = 0; pthread_mutex_unlock(&mutex); + pthread_mutex_lock(&mutex_new); + pthread_cond_wait(&cond_new, &mutex_new); + pthread_mutex_unlock(&mutex_new); + goto restart; + return NULL; } #endif -- 2.7.4