From 0c317eaca288a546124677247952f3962a7117fb Mon Sep 17 00:00:00 2001 From: Sebastian Dransfeld Date: Thu, 20 Jun 2013 11:55:38 +0200 Subject: [PATCH] efreet: Make _path_to_file_id threadsafe --- src/lib/efreet/efreet_utils.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lib/efreet/efreet_utils.c b/src/lib/efreet/efreet_utils.c index 87f418b..a0bc37c 100644 --- a/src/lib/efreet/efreet_utils.c +++ b/src/lib/efreet/efreet_utils.c @@ -25,6 +25,8 @@ static Efreet_Desktop *efreet_util_cache_find(const char *search, const char *wh static Eina_List *efreet_util_cache_list(const char *search, const char *what); static Eina_List *efreet_util_cache_glob_list(const char *search, const char *what); +static Eina_Lock _lock; + static Eina_Hash *file_id_by_desktop_path = NULL; static int init = 0; @@ -41,9 +43,20 @@ efreet_util_init(void) return 0; } + if (!eina_lock_new(&_lock)) + { + ERR("Could not create lock"); + goto error; + } + + file_id_by_desktop_path = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del)); return init; +error: + eina_log_domain_unregister(_efreet_utils_log_dom); + _efreet_utils_log_dom = -1; + return 0; } int @@ -51,6 +64,8 @@ efreet_util_shutdown(void) { if (--init) return init; + eina_lock_free(&_lock); + eina_log_domain_unregister(_efreet_utils_log_dom); _efreet_utils_log_dom = -1; IF_FREE_HASH(file_id_by_desktop_path); @@ -118,7 +133,9 @@ efreet_util_path_to_file_id(const char *path) } eina_stringshare_del(base); file_id = eina_stringshare_add(tmp); - eina_hash_add(file_id_by_desktop_path, path, (void *)file_id); + eina_lock_take(&_lock); + eina_hash_set(file_id_by_desktop_path, path, (void *)file_id); + eina_lock_release(&_lock); return file_id; } -- 2.7.4