summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-06-25 11:42:14 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-06-25 11:45:42 +0900
commit406cdbd686cfcedea26c0aa1bee876c95af666ec (patch)
treefe8dc3eceba50cb87cfba735fcf2963c18e67ace
parentc11e4cbca8eb097945f0b2973d17ac5c85b9789f (diff)
evas: one LRU for both image open with filename or Eina_File to fix infinite increase of cache.
-rw-r--r--src/lib/evas/cache/evas_cache.h2
-rw-r--r--src/lib/evas/cache/evas_cache_image.c27
2 files changed, 10 insertions, 19 deletions
diff --git a/src/lib/evas/cache/evas_cache.h b/src/lib/evas/cache/evas_cache.h
index 785649ae68..88abc24b7f 100644
--- a/src/lib/evas/cache/evas_cache.h
+++ b/src/lib/evas/cache/evas_cache.h
@@ -56,8 +56,6 @@ struct _Evas_Cache_Image
56 56
57 Eina_Hash *mmap_activ; 57 Eina_Hash *mmap_activ;
58 Eina_Hash *mmap_inactiv; 58 Eina_Hash *mmap_inactiv;
59 Eina_Inlist *mmap_lru;
60 Eina_Inlist *mmap_lru_nodata;
61 59
62 void *data; 60 void *data;
63 61
diff --git a/src/lib/evas/cache/evas_cache_image.c b/src/lib/evas/cache/evas_cache_image.c
index fd8af538e4..d5e58e2882 100644
--- a/src/lib/evas/cache/evas_cache_image.c
+++ b/src/lib/evas/cache/evas_cache_image.c
@@ -119,13 +119,12 @@ _evas_cache_image_lru_add(Image_Entry *im)
119 if (im->flags.given_mmap) 119 if (im->flags.given_mmap)
120 { 120 {
121 eina_hash_direct_add(im->cache->mmap_inactiv, im->cache_key, im); 121 eina_hash_direct_add(im->cache->mmap_inactiv, im->cache_key, im);
122 im->cache->mmap_lru = eina_inlist_prepend(im->cache->mmap_lru, EINA_INLIST_GET(im));
123 } 122 }
124 else 123 else
125 { 124 {
126 eina_hash_direct_add(im->cache->inactiv, im->cache_key, im); 125 eina_hash_direct_add(im->cache->inactiv, im->cache_key, im);
127 im->cache->lru = eina_inlist_prepend(im->cache->lru, EINA_INLIST_GET(im));
128 } 126 }
127 im->cache->lru = eina_inlist_prepend(im->cache->lru, EINA_INLIST_GET(im));
129 im->cache->usage += im->cache->func.mem_size_get(im); 128 im->cache->usage += im->cache->func.mem_size_get(im);
130} 129}
131 130
@@ -139,13 +138,12 @@ _evas_cache_image_lru_del(Image_Entry *im)
139 if (im->flags.given_mmap) 138 if (im->flags.given_mmap)
140 { 139 {
141 eina_hash_del(im->cache->mmap_inactiv, im->cache_key, im); 140 eina_hash_del(im->cache->mmap_inactiv, im->cache_key, im);
142 im->cache->mmap_lru = eina_inlist_remove(im->cache->mmap_lru, EINA_INLIST_GET(im));
143 } 141 }
144 else 142 else
145 { 143 {
146 eina_hash_del(im->cache->inactiv, im->cache_key, im); 144 eina_hash_del(im->cache->inactiv, im->cache_key, im);
147 im->cache->lru = eina_inlist_remove(im->cache->lru, EINA_INLIST_GET(im));
148 } 145 }
146 im->cache->lru = eina_inlist_remove(im->cache->lru, EINA_INLIST_GET(im));
149 im->cache->usage -= im->cache->func.mem_size_get(im); 147 im->cache->usage -= im->cache->func.mem_size_get(im);
150} 148}
151 149
@@ -158,10 +156,7 @@ _evas_cache_image_lru_nodata_add(Image_Entry *im)
158 _evas_cache_image_lru_del(im); 156 _evas_cache_image_lru_del(im);
159 im->flags.lru = 1; 157 im->flags.lru = 1;
160 im->flags.cached = 1; 158 im->flags.cached = 1;
161 if (im->flags.given_mmap) 159 im->cache->lru_nodata = eina_inlist_prepend(im->cache->lru_nodata, EINA_INLIST_GET(im));
162 im->cache->mmap_lru_nodata = eina_inlist_prepend(im->cache->mmap_lru_nodata, EINA_INLIST_GET(im));
163 else
164 im->cache->lru_nodata = eina_inlist_prepend(im->cache->lru_nodata, EINA_INLIST_GET(im));
165} 160}
166 161
167static void 162static void
@@ -170,10 +165,7 @@ _evas_cache_image_lru_nodata_del(Image_Entry *im)
170 if (!im->flags.lru_nodata) return; 165 if (!im->flags.lru_nodata) return;
171 im->flags.lru = 0; 166 im->flags.lru = 0;
172 im->flags.cached = 0; 167 im->flags.cached = 0;
173 if (im->flags.given_mmap) 168 im->cache->lru_nodata = eina_inlist_remove(im->cache->lru_nodata, EINA_INLIST_GET(im));
174 im->cache->mmap_lru_nodata = eina_inlist_remove(im->cache->mmap_lru_nodata, EINA_INLIST_GET(im));
175 else
176 im->cache->lru_nodata = eina_inlist_remove(im->cache->lru_nodata, EINA_INLIST_GET(im));
177} 169}
178 170
179static void 171static void
@@ -181,6 +173,7 @@ _evas_cache_image_entry_delete(Evas_Cache_Image *cache, Image_Entry *ie)
181{ 173{
182 Image_Entry_Task *task; 174 Image_Entry_Task *task;
183 175
176 fprintf(stderr, "delete entry %p %p\n", ie, ie->f);
184 if (!ie) return; 177 if (!ie) return;
185 if ((cache) && (cache->func.debug)) cache->func.debug("deleting", ie); 178 if ((cache) && (cache->func.debug)) cache->func.debug("deleting", ie);
186 if (ie->flags.delete_me == 1) return; 179 if (ie->flags.delete_me == 1) return;
@@ -203,6 +196,7 @@ _evas_cache_image_entry_delete(Evas_Cache_Image *cache, Image_Entry *ie)
203 FREESTRC(ie->cache_key); 196 FREESTRC(ie->cache_key);
204 FREESTRC(ie->file); 197 FREESTRC(ie->file);
205 FREESTRC(ie->key); 198 FREESTRC(ie->key);
199 if (ie->f && ie->flags.given_mmap) eina_file_close(ie->f);
206 ie->cache = NULL; 200 ie->cache = NULL;
207 cache->func.surface_delete(ie); 201 cache->func.surface_delete(ie);
208 202
@@ -270,7 +264,7 @@ _evas_cache_image_entry_new(Evas_Cache_Image *cache,
270 ie->w = -1; 264 ie->w = -1;
271 ie->h = -1; 265 ie->h = -1;
272 ie->scale = 1; 266 ie->scale = 1;
273 ie->f = f; 267 ie->f = eina_file_dup(f);
274 ie->loader_data = NULL; 268 ie->loader_data = NULL;
275 if (ie->f) ie->flags.given_mmap = EINA_TRUE; 269 if (ie->f) ie->flags.given_mmap = EINA_TRUE;
276 if (file) ie->file = eina_stringshare_add(file); 270 if (file) ie->file = eina_stringshare_add(file);
@@ -620,10 +614,6 @@ evas_cache_image_shutdown(Evas_Cache_Image *cache)
620 _evas_cache_image_entry_delete(cache, im); 614 _evas_cache_image_entry_delete(cache, im);
621 EINA_INLIST_FREE(cache->lru_nodata, im) 615 EINA_INLIST_FREE(cache->lru_nodata, im)
622 _evas_cache_image_entry_delete(cache, im); 616 _evas_cache_image_entry_delete(cache, im);
623 EINA_INLIST_FREE(cache->mmap_lru, im)
624 _evas_cache_image_entry_delete(cache, im);
625 EINA_INLIST_FREE(cache->mmap_lru_nodata, im)
626 _evas_cache_image_entry_delete(cache, im);
627 617
628 /* This is mad, I am about to destroy image still alive, but we need to prevent leak. */ 618 /* This is mad, I am about to destroy image still alive, but we need to prevent leak. */
629 while (cache->dirty) 619 while (cache->dirty)
@@ -793,6 +783,7 @@ evas_cache_image_mmap_request(Evas_Cache_Image *cache,
793 if (!im) return NULL; 783 if (!im) return NULL;
794 784
795 on_ok: 785 on_ok:
786 fprintf(stderr, "new ref: %i\n", im->references);
796 *error = EVAS_LOAD_ERROR_NONE; 787 *error = EVAS_LOAD_ERROR_NONE;
797 im->references++; 788 im->references++;
798 return im; 789 return im;
@@ -945,6 +936,8 @@ evas_cache_image_drop(Image_Entry *im)
945 936
946 cache = im->cache; 937 cache = im->cache;
947 938
939 fprintf(stderr, "%p ref: %i, im->f: %p, cache: %p\n",
940 im, references, im->f, cache);
948 if (references == 0) 941 if (references == 0)
949 { 942 {
950 if (im->preload) 943 if (im->preload)