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.



SVN revision: 38746
This commit is contained in:
Gustavo Sverzut Barbieri 2009-01-23 20:36:04 +00:00
parent 8bee601e8d
commit 14a88b52d4
1 changed files with 21 additions and 6 deletions

View File

@ -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