summaryrefslogtreecommitdiff
path: root/src/lib/efreet
diff options
context:
space:
mode:
authorSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-06-20 11:52:43 +0200
committerSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-06-20 11:56:46 +0200
commitceb19aaaaa659da98655574b2bbea88288e78555 (patch)
tree51da46c620644108ed8ca16201e0c45476db32c2 /src/lib/efreet
parent39417cf0ea4e457fbc8d50d120bb8ac776aa366f (diff)
efreet: Make desktop cache threadsafe
Diffstat (limited to 'src/lib/efreet')
-rw-r--r--src/lib/efreet/efreet_cache.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/lib/efreet/efreet_cache.c b/src/lib/efreet/efreet_cache.c
index 3e145d0df9..8af3780158 100644
--- a/src/lib/efreet/efreet_cache.c
+++ b/src/lib/efreet/efreet_cache.c
@@ -42,6 +42,9 @@ struct _Efreet_Old_Cache
42 42
43static Eldbus_Connection *conn = NULL; 43static Eldbus_Connection *conn = NULL;
44static Eldbus_Proxy *proxy = NULL; 44static Eldbus_Proxy *proxy = NULL;
45
46static Eina_Lock _lock;
47
45/** 48/**
46 * Data for cache files 49 * Data for cache files
47 */ 50 */
@@ -112,6 +115,12 @@ efreet_cache_init(void)
112 if (_efreet_cache_log_dom < 0) 115 if (_efreet_cache_log_dom < 0)
113 return 0; 116 return 0;
114 117
118 if (!eina_lock_new(&_lock))
119 {
120 ERR("Could not create lock");
121 goto error;
122 }
123
115 EFREET_EVENT_ICON_CACHE_UPDATE = ecore_event_type_new(); 124 EFREET_EVENT_ICON_CACHE_UPDATE = ecore_event_type_new();
116 EFREET_EVENT_DESKTOP_CACHE_UPDATE = ecore_event_type_new(); 125 EFREET_EVENT_DESKTOP_CACHE_UPDATE = ecore_event_type_new();
117 EFREET_EVENT_DESKTOP_CACHE_BUILD = ecore_event_type_new(); 126 EFREET_EVENT_DESKTOP_CACHE_BUILD = ecore_event_type_new();
@@ -217,6 +226,8 @@ efreet_cache_shutdown(void)
217 226
218 eldbus_shutdown(); 227 eldbus_shutdown();
219 228
229 eina_lock_free(&_lock);
230
220 eina_log_domain_unregister(_efreet_cache_log_dom); 231 eina_log_domain_unregister(_efreet_cache_log_dom);
221 _efreet_cache_log_dom = -1; 232 _efreet_cache_log_dom = -1;
222} 233}
@@ -767,24 +778,27 @@ efreet_cache_array_string_free(Efreet_Cache_Array_String *array)
767Efreet_Desktop * 778Efreet_Desktop *
768efreet_cache_desktop_find(const char *file) 779efreet_cache_desktop_find(const char *file)
769{ 780{
770 Efreet_Cache_Desktop *cache; 781 Efreet_Cache_Desktop *cache = NULL;
771 782
772 if (!efreet_cache_check(&desktop_cache, efreet_desktop_cache_file(), EFREET_DESKTOP_CACHE_MAJOR)) return NULL; 783 eina_lock_take(&_lock);
784 if (!efreet_cache_check(&desktop_cache, efreet_desktop_cache_file(), EFREET_DESKTOP_CACHE_MAJOR)) goto error;
773 785
774 cache = eina_hash_find(desktops, file); 786 cache = eina_hash_find(desktops, file);
775 if (cache == NON_EXISTING) return NULL; 787 if (cache == NON_EXISTING) goto error;
776 if (cache) 788 if (cache)
777 { 789 {
778 /* If less than one second since last stat, return desktop */ 790 /* If less than one second since last stat, return desktop */
779 if ((ecore_time_get() - cache->check_time) < 1) 791 if ((ecore_time_get() - cache->check_time) < 1)
780 { 792 {
781 INF("Return without stat %f %f", ecore_time_get(), cache->check_time); 793 INF("Return without stat %f %f", ecore_time_get(), cache->check_time);
794 eina_lock_release(&_lock);
782 return &cache->desktop; 795 return &cache->desktop;
783 } 796 }
784 if (cache->desktop.load_time == ecore_file_mod_time(cache->desktop.orig_path)) 797 if (cache->desktop.load_time == ecore_file_mod_time(cache->desktop.orig_path))
785 { 798 {
786 INF("Return with stat %f %f", ecore_time_get(), cache->check_time); 799 INF("Return with stat %f %f", ecore_time_get(), cache->check_time);
787 cache->check_time = ecore_time_get(); 800 cache->check_time = ecore_time_get();
801 eina_lock_release(&_lock);
788 return &cache->desktop; 802 return &cache->desktop;
789 } 803 }
790 804
@@ -809,11 +823,14 @@ efreet_cache_desktop_find(const char *file)
809 cache->desktop.eet = 1; 823 cache->desktop.eet = 1;
810 cache->check_time = ecore_time_get(); 824 cache->check_time = ecore_time_get();
811 eina_hash_set(desktops, cache->desktop.orig_path, cache); 825 eina_hash_set(desktops, cache->desktop.orig_path, cache);
826 eina_lock_release(&_lock);
812 return &cache->desktop; 827 return &cache->desktop;
813 } 828 }
814 } 829 }
815 else 830 else
816 eina_hash_set(desktops, file, NON_EXISTING); 831 eina_hash_set(desktops, file, NON_EXISTING);
832error:
833 eina_lock_release(&_lock);
817 return NULL; 834 return NULL;
818} 835}
819 836
@@ -828,6 +845,7 @@ efreet_cache_desktop_free(Efreet_Desktop *desktop)
828 desktop == NON_EXISTING || 845 desktop == NON_EXISTING ||
829 !desktop->eet) return; 846 !desktop->eet) return;
830 847
848 eina_lock_take(&_lock);
831 curr = eina_hash_find(desktops, desktop->orig_path); 849 curr = eina_hash_find(desktops, desktop->orig_path);
832 if (curr == desktop) 850 if (curr == desktop)
833 { 851 {
@@ -860,6 +878,7 @@ efreet_cache_desktop_free(Efreet_Desktop *desktop)
860 eina_list_free(desktop->mime_types); 878 eina_list_free(desktop->mime_types);
861 IF_FREE_HASH(desktop->x); 879 IF_FREE_HASH(desktop->x);
862 free(desktop); 880 free(desktop);
881 eina_lock_release(&_lock);
863} 882}
864 883
865void 884void
@@ -871,6 +890,12 @@ efreet_cache_desktop_add(Efreet_Desktop *desktop)
871 890
872 if (!efreet_cache_update) return; 891 if (!efreet_cache_update) return;
873 /* TODO: Chunk updates */ 892 /* TODO: Chunk updates */
893 if (!eina_main_loop_is()) return;
894 /*
895 * TODO: Call in thread with:
896 ecore_thread_main_loop_begin();
897 ecore_thread_main_loop_end();
898 */
874 path = ecore_file_dir_get(desktop->orig_path); 899 path = ecore_file_dir_get(desktop->orig_path);
875 msg = eldbus_proxy_method_call_new(proxy, "AddDesktopDirs"); 900 msg = eldbus_proxy_method_call_new(proxy, "AddDesktopDirs");
876 iter = eldbus_message_iter_get(msg); 901 iter = eldbus_message_iter_get(msg);
@@ -923,6 +948,7 @@ efreet_cache_desktop_close(void)
923 IF_RELEASE(util_cache_names_key); 948 IF_RELEASE(util_cache_names_key);
924 IF_RELEASE(util_cache_hash_key); 949 IF_RELEASE(util_cache_hash_key);
925 950
951 eina_lock_take(&_lock);
926 if ((desktop_cache) && (desktop_cache != NON_EXISTING)) 952 if ((desktop_cache) && (desktop_cache != NON_EXISTING))
927 { 953 {
928 Efreet_Old_Cache *d = NEW(Efreet_Old_Cache, 1); 954 Efreet_Old_Cache *d = NEW(Efreet_Old_Cache, 1);
@@ -936,6 +962,7 @@ efreet_cache_desktop_close(void)
936 desktops = eina_hash_string_superfast_new(NULL); 962 desktops = eina_hash_string_superfast_new(NULL);
937 } 963 }
938 desktop_cache = NULL; 964 desktop_cache = NULL;
965 eina_lock_release(&_lock);
939 966
940 efreet_cache_array_string_free(util_cache_names); 967 efreet_cache_array_string_free(util_cache_names);
941 util_cache_names = NULL; 968 util_cache_names = NULL;
@@ -949,7 +976,9 @@ efreet_cache_desktop_close(void)
949 976
950 util_cache = efreet_cache_close(util_cache); 977 util_cache = efreet_cache_close(util_cache);
951 978
979 eina_lock_take(&_lock);
952 IF_RELEASE(desktop_cache_file); 980 IF_RELEASE(desktop_cache_file);
981 eina_lock_release(&_lock);
953 IF_RELEASE(util_cache_file); 982 IF_RELEASE(util_cache_file);
954} 983}
955 984