summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2010-11-18 09:54:51 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2010-11-18 09:54:51 +0000
commitc0a91f492e66cf32815a0e0ba578895d57c5a9bf (patch)
tree7c8a66ff62e3178ea70edc7410ebe2c4c1e90910 /src/bin
parenta909601cfb30250b7c99eec08f5d8175535fe753 (diff)
allow fetch to be executed from main thread as well.
SVN revision: 54676
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/test_store.c58
1 files changed, 46 insertions, 12 deletions
diff --git a/src/bin/test_store.c b/src/bin/test_store.c
index bf29d9277..a010e040c 100644
--- a/src/bin/test_store.c
+++ b/src/bin/test_store.c
@@ -46,6 +46,9 @@ EAPI void elm_store_cache_set(Elm_Store *st, int max);
46EAPI int elm_store_cache_get(const Elm_Store *st); 46EAPI int elm_store_cache_get(const Elm_Store *st);
47EAPI void elm_store_list_func_set(Elm_Store *st, Elm_Store_Item_List_Cb func, const void *data); 47EAPI void elm_store_list_func_set(Elm_Store *st, Elm_Store_Item_List_Cb func, const void *data);
48EAPI void elm_store_fetch_func_set(Elm_Store *st, Elm_Store_Item_Fetch_Cb func, const void *data); 48EAPI void elm_store_fetch_func_set(Elm_Store *st, Elm_Store_Item_Fetch_Cb func, const void *data);
49EAPI void elm_store_fetch_thread_set(Elm_Store *st, Eina_Bool use_thread);
50EAPI Eina_Bool elm_store_fetch_thread_get(const Elm_Store *st);
51
49EAPI void elm_store_unfetch_func_set(Elm_Store *st, Elm_Store_Item_Unfetch_Cb func, const void *data); 52EAPI void elm_store_unfetch_func_set(Elm_Store *st, Elm_Store_Item_Unfetch_Cb func, const void *data);
50EAPI void elm_store_sorted_set(Elm_Store *st, Eina_Bool sorted); 53EAPI void elm_store_sorted_set(Elm_Store *st, Eina_Bool sorted);
51EAPI Eina_Bool elm_store_sorted_get(const Elm_Store *st); 54EAPI Eina_Bool elm_store_sorted_get(const Elm_Store *st);
@@ -55,7 +58,7 @@ EAPI const Elm_Store *elm_store_item_store_get(const Elm_Store_Item *sti)
55EAPI const Elm_Genlist_Item *elm_store_item_genlist_item_get(const Elm_Store_Item *sti); 58EAPI const Elm_Genlist_Item *elm_store_item_genlist_item_get(const Elm_Store_Item *sti);
56 59
57// private 60// private
58#if 0 61#if 1
59#define DBG(f, args...) printf(f, ##args) 62#define DBG(f, args...) printf(f, ##args)
60#else 63#else
61#define DBG(f, args...) 64#define DBG(f, args...)
@@ -94,6 +97,7 @@ struct _Elm_Store
94 } unfetch; 97 } unfetch;
95 } cb; 98 } cb;
96 Eina_Bool sorted : 1; 99 Eina_Bool sorted : 1;
100 Eina_Bool fetch_thread : 1;
97}; 101};
98 102
99struct _Elm_Store_Item 103struct _Elm_Store_Item
@@ -157,14 +161,17 @@ _store_cache_trim(Elm_Store *st)
157 LKL(sti->lock); 161 LKL(sti->lock);
158 if (!sti->fetched) 162 if (!sti->fetched)
159 { 163 {
160 DBG(".. do cancel [%i] [%i] %p for: %s\n",
161 sti->live,
162 sti->fetched,
163 sti->fetch_th,
164 elm_store_item_filesystem_path_get(sti));
165 LKU(sti->lock); 164 LKU(sti->lock);
166 ecore_thread_cancel(sti->fetch_th); 165 if (sti->fetch_th)
167 sti->fetch_th = NULL; 166 {
167 DBG(".. do cancel [%i] [%i] %p for: %s\n",
168 sti->live,
169 sti->fetched,
170 sti->fetch_th,
171 elm_store_item_filesystem_path_get(sti));
172 ecore_thread_cancel(sti->fetch_th);
173 sti->fetch_th = NULL;
174 }
168 LKL(sti->lock); 175 LKL(sti->lock);
169 } 176 }
170 sti->fetched = EINA_FALSE; 177 sti->fetched = EINA_FALSE;
@@ -218,6 +225,7 @@ _store_genlist_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
218////// **** WARNING *********************************************************** 225////// **** WARNING ***********************************************************
219//// * This function runs inside a thread outside efl mainloop. Be careful! * 226//// * This function runs inside a thread outside efl mainloop. Be careful! *
220// ************************************************************************ 227// ************************************************************************
228/* TODO: refactor lock part into core? this does not depend on filesystm part */
221static void 229static void
222_store_filesystem_fetch_do(void *data, Ecore_Thread *th __UNUSED__) 230_store_filesystem_fetch_do(void *data, Ecore_Thread *th __UNUSED__)
223{ 231{
@@ -241,7 +249,7 @@ _store_filesystem_fetch_do(void *data, Ecore_Thread *th __UNUSED__)
241// ************************************************************************ 249// ************************************************************************
242//// * End of separate thread function. * 250//// * End of separate thread function. *
243////// ************************************************************************ 251////// ************************************************************************
244 252/* TODO: refactor lock part into core? this does not depend on filesystm part */
245static void 253static void
246_store_filesystem_fetch_end(void *data, Ecore_Thread *th) 254_store_filesystem_fetch_end(void *data, Ecore_Thread *th)
247{ 255{
@@ -256,6 +264,7 @@ _store_filesystem_fetch_end(void *data, Ecore_Thread *th)
256 if (th == sti->fetch_th) sti->fetch_th = NULL; 264 if (th == sti->fetch_th) sti->fetch_th = NULL;
257} 265}
258 266
267/* TODO: refactor lock part into core? this does not depend on filesystm part */
259static void 268static void
260_store_filesystem_fetch_cancel(void *data, Ecore_Thread *th) 269_store_filesystem_fetch_cancel(void *data, Ecore_Thread *th)
261{ 270{
@@ -285,7 +294,7 @@ _store_item_eval(void *data)
285 sti->store->realized = eina_list_remove(sti->store->realized, sti); 294 sti->store->realized = eina_list_remove(sti->store->realized, sti);
286 sti->store->realized = eina_list_append(sti->store->realized, sti); 295 sti->store->realized = eina_list_append(sti->store->realized, sti);
287 sti->realized = EINA_TRUE; 296 sti->realized = EINA_TRUE;
288 if (!sti->fetch_th) 297 if ((sti->store->fetch_thread) && (!sti->fetch_th))
289 { 298 {
290 sti->fetch_th = ecore_thread_run(_store_filesystem_fetch_do, 299 sti->fetch_th = ecore_thread_run(_store_filesystem_fetch_do,
291 _store_filesystem_fetch_end, 300 _store_filesystem_fetch_end,
@@ -297,6 +306,16 @@ _store_item_eval(void *data)
297 sti->fetch_th, 306 sti->fetch_th,
298 elm_store_item_filesystem_path_get(sti)); 307 elm_store_item_filesystem_path_get(sti));
299 } 308 }
309 else if ((!sti->store->fetch_thread))
310 {
311 DBG(".. do fetch in same thread [%i] [%i] = %p for: %s\n",
312 sti->live,
313 sti->fetched,
314 sti->fetch_th,
315 elm_store_item_filesystem_path_get(sti));
316 _store_filesystem_fetch_do(sti, NULL);
317 _store_filesystem_fetch_end(sti, NULL);
318 }
300 } 319 }
301 else 320 else
302 { 321 {
@@ -514,6 +533,7 @@ _elm_store_new(size_t size)
514 533
515 EINA_MAGIC_SET(st, ELM_STORE_MAGIC); 534 EINA_MAGIC_SET(st, ELM_STORE_MAGIC);
516 st->cache_max = 128; 535 st->cache_max = 128;
536 st->fetch_thread = EINA_TRUE;
517 return st; 537 return st;
518} 538}
519#define elm_store_new(type) (type*)_elm_store_new(sizeof(type)) 539#define elm_store_new(type) (type*)_elm_store_new(sizeof(type))
@@ -682,6 +702,20 @@ elm_store_fetch_func_set(Elm_Store *st, Elm_Store_Item_Fetch_Cb func, const void
682} 702}
683 703
684EAPI void 704EAPI void
705elm_store_fetch_thread_set(Elm_Store *st, Eina_Bool use_thread)
706{
707 if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
708 st->fetch_thread = !!use_thread;
709}
710
711EAPI Eina_Bool
712elm_store_fetch_thread_get(const Elm_Store *st)
713{
714 if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return EINA_FALSE;
715 return st->fetch_thread;
716}
717
718EAPI void
685elm_store_unfetch_func_set(Elm_Store *st, Elm_Store_Item_Unfetch_Cb func, const void *data) 719elm_store_unfetch_func_set(Elm_Store *st, Elm_Store_Item_Unfetch_Cb func, const void *data)
686{ 720{
687 if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return; 721 if (!EINA_MAGIC_CHECK(st, ELM_STORE_MAGIC)) return;
@@ -978,11 +1012,11 @@ test_store(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info
978 st = elm_store_filesystem_new(); 1012 st = elm_store_filesystem_new();
979 elm_store_list_func_set(st, _st_store_list, NULL); 1013 elm_store_list_func_set(st, _st_store_list, NULL);
980 elm_store_fetch_func_set(st, _st_store_fetch, NULL); 1014 elm_store_fetch_func_set(st, _st_store_fetch, NULL);
1015 //elm_store_fetch_thread_set(st, EINA_FALSE);
981 elm_store_unfetch_func_set(st, _st_store_unfetch, NULL); 1016 elm_store_unfetch_func_set(st, _st_store_unfetch, NULL);
982 elm_store_sorted_set(st, EINA_TRUE); 1017 elm_store_sorted_set(st, EINA_TRUE);
983 elm_store_target_genlist_set(st, gl); 1018 elm_store_target_genlist_set(st, gl);
984 // elm_store_filesystem_directory_set(st, "/home/raster/tst"); 1019 elm_store_filesystem_directory_set(st, "/home/raster/tst");
985 elm_store_filesystem_directory_set(st, "/tmp/tst");
986 1020
987 evas_object_resize(win, 480, 800); 1021 evas_object_resize(win, 480, 800);
988 evas_object_show(win); 1022 evas_object_show(win);