summaryrefslogtreecommitdiff
path: root/src/lib/efreet/efreet_desktop.c
diff options
context:
space:
mode:
authorSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-06-20 11:29:28 +0200
committerSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-06-20 11:56:46 +0200
commit39417cf0ea4e457fbc8d50d120bb8ac776aa366f (patch)
tree65529d5b774def2465507576d74f2ef8b164ba63 /src/lib/efreet/efreet_desktop.c
parent5efd817e57713ac3ac17fbc4f764043ade2e547c (diff)
efreet: Make efreet_desktop threadsafe
Diffstat (limited to '')
-rw-r--r--src/lib/efreet/efreet_desktop.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/lib/efreet/efreet_desktop.c b/src/lib/efreet/efreet_desktop.c
index 780ff9a9a6..35e20e07c5 100644
--- a/src/lib/efreet/efreet_desktop.c
+++ b/src/lib/efreet/efreet_desktop.c
@@ -27,6 +27,8 @@ static const char *desktop_environment = NULL;
27 */ 27 */
28static Eina_List *efreet_desktop_types = NULL; 28static Eina_List *efreet_desktop_types = NULL;
29 29
30static Eina_Lock _lock;
31
30EAPI int EFREET_DESKTOP_TYPE_APPLICATION = 0; 32EAPI int EFREET_DESKTOP_TYPE_APPLICATION = 0;
31EAPI int EFREET_DESKTOP_TYPE_LINK = 0; 33EAPI int EFREET_DESKTOP_TYPE_LINK = 0;
32EAPI int EFREET_DESKTOP_TYPE_DIRECTORY = 0; 34EAPI int EFREET_DESKTOP_TYPE_DIRECTORY = 0;
@@ -94,6 +96,12 @@ efreet_desktop_init(void)
94 } 96 }
95#endif 97#endif
96 98
99 if (!eina_lock_new(&_lock))
100 {
101 ERR("Could not create lock");
102 goto error;
103 }
104
97 efreet_desktop_types = NULL; 105 efreet_desktop_types = NULL;
98 106
99 EFREET_DESKTOP_TYPE_APPLICATION = efreet_desktop_type_add("Application", 107 EFREET_DESKTOP_TYPE_APPLICATION = efreet_desktop_type_add("Application",
@@ -107,12 +115,10 @@ efreet_desktop_init(void)
107 NULL, NULL); 115 NULL, NULL);
108 116
109 return 1; 117 return 1;
110#ifdef HAVE_EVIL
111error: 118error:
112 eina_log_domain_unregister(_efreet_desktop_log_dom); 119 eina_log_domain_unregister(_efreet_desktop_log_dom);
113 _efreet_desktop_log_dom = -1; 120 _efreet_desktop_log_dom = -1;
114 return 0; 121 return 0;
115#endif
116} 122}
117 123
118/** 124/**
@@ -128,6 +134,7 @@ efreet_desktop_shutdown(void)
128 IF_RELEASE(desktop_environment); 134 IF_RELEASE(desktop_environment);
129 EINA_LIST_FREE(efreet_desktop_types, info) 135 EINA_LIST_FREE(efreet_desktop_types, info)
130 efreet_desktop_type_info_free(info); 136 efreet_desktop_type_info_free(info);
137 eina_lock_free(&_lock);
131#ifdef HAVE_EVIL 138#ifdef HAVE_EVIL
132 evil_sockets_shutdown(); 139 evil_sockets_shutdown();
133#endif 140#endif
@@ -168,7 +175,9 @@ EAPI int
168efreet_desktop_ref(Efreet_Desktop *desktop) 175efreet_desktop_ref(Efreet_Desktop *desktop)
169{ 176{
170 EINA_SAFETY_ON_NULL_RETURN_VAL(desktop, 0); 177 EINA_SAFETY_ON_NULL_RETURN_VAL(desktop, 0);
178 eina_lock_take(&_lock);
171 desktop->ref++; 179 desktop->ref++;
180 eina_lock_release(&_lock);
172 return desktop->ref; 181 return desktop->ref;
173} 182}
174 183
@@ -205,7 +214,9 @@ efreet_desktop_new(const char *file)
205 free(tmp); 214 free(tmp);
206 if (desktop) 215 if (desktop)
207 { 216 {
217 eina_lock_take(&_lock);
208 desktop->ref++; 218 desktop->ref++;
219 eina_lock_release(&_lock);
209 if (!efreet_desktop_environment_check(desktop)) 220 if (!efreet_desktop_environment_check(desktop))
210 { 221 {
211 efreet_desktop_free(desktop); 222 efreet_desktop_free(desktop);
@@ -320,8 +331,13 @@ efreet_desktop_free(Efreet_Desktop *desktop)
320{ 331{
321 if (!desktop) return; 332 if (!desktop) return;
322 333
334 eina_lock_take(&_lock);
323 desktop->ref--; 335 desktop->ref--;
324 if (desktop->ref > 0) return; 336 if (desktop->ref > 0)
337 {
338 eina_lock_release(&_lock);
339 return;
340 }
325 341
326 if (desktop->eet) 342 if (desktop->eet)
327 { 343 {
@@ -360,6 +376,7 @@ efreet_desktop_free(Efreet_Desktop *desktop)
360 } 376 }
361 free(desktop); 377 free(desktop);
362 } 378 }
379 eina_lock_release(&_lock);
363} 380}
364 381
365EAPI void 382EAPI void
@@ -392,8 +409,10 @@ efreet_desktop_category_add(Efreet_Desktop *desktop, const char *category)
392 if (eina_list_search_unsorted(desktop->categories, 409 if (eina_list_search_unsorted(desktop->categories,
393 EINA_COMPARE_CB(strcmp), category)) return; 410 EINA_COMPARE_CB(strcmp), category)) return;
394 411
412 eina_lock_take(&_lock);
395 desktop->categories = eina_list_append(desktop->categories, 413 desktop->categories = eina_list_append(desktop->categories,
396 (void *)eina_stringshare_add(category)); 414 (void *)eina_stringshare_add(category));
415 eina_lock_release(&_lock);
397} 416}
398 417
399EAPI int 418EAPI int
@@ -406,8 +425,10 @@ efreet_desktop_category_del(Efreet_Desktop *desktop, const char *category)
406 if ((found = eina_list_search_unsorted(desktop->categories, 425 if ((found = eina_list_search_unsorted(desktop->categories,
407 EINA_COMPARE_CB(strcmp), category))) 426 EINA_COMPARE_CB(strcmp), category)))
408 { 427 {
409 eina_stringshare_del(found); 428 eina_lock_take(&_lock);
410 desktop->categories = eina_list_remove(desktop->categories, found); 429 desktop->categories = eina_list_remove(desktop->categories, found);
430 eina_stringshare_del(found);
431 eina_lock_release(&_lock);
411 432
412 return 1; 433 return 1;
413 } 434 }
@@ -455,11 +476,13 @@ efreet_desktop_x_field_set(Efreet_Desktop *desktop, const char *key, const char
455 EINA_SAFETY_ON_NULL_RETURN_VAL(desktop, EINA_FALSE); 476 EINA_SAFETY_ON_NULL_RETURN_VAL(desktop, EINA_FALSE);
456 EINA_SAFETY_ON_TRUE_RETURN_VAL(strncmp(key, "X-", 2), EINA_FALSE); 477 EINA_SAFETY_ON_TRUE_RETURN_VAL(strncmp(key, "X-", 2), EINA_FALSE);
457 478
479 eina_lock_take(&_lock);
458 if (!desktop->x) 480 if (!desktop->x)
459 desktop->x = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del)); 481 desktop->x = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
460 482
461 eina_hash_del_by_key(desktop->x, key); 483 eina_hash_del_by_key(desktop->x, key);
462 eina_hash_add(desktop->x, key, eina_stringshare_add(data)); 484 eina_hash_add(desktop->x, key, eina_stringshare_add(data));
485 eina_lock_release(&_lock);
463 486
464 return EINA_TRUE; 487 return EINA_TRUE;
465} 488}
@@ -483,11 +506,15 @@ efreet_desktop_x_field_get(Efreet_Desktop *desktop, const char *key)
483EAPI Eina_Bool 506EAPI Eina_Bool
484efreet_desktop_x_field_del(Efreet_Desktop *desktop, const char *key) 507efreet_desktop_x_field_del(Efreet_Desktop *desktop, const char *key)
485{ 508{
509 Eina_Bool ret;
486 EINA_SAFETY_ON_NULL_RETURN_VAL(desktop, EINA_FALSE); 510 EINA_SAFETY_ON_NULL_RETURN_VAL(desktop, EINA_FALSE);
487 EINA_SAFETY_ON_TRUE_RETURN_VAL(strncmp(key, "X-", 2), EINA_FALSE); 511 EINA_SAFETY_ON_TRUE_RETURN_VAL(strncmp(key, "X-", 2), EINA_FALSE);
488 EINA_SAFETY_ON_NULL_RETURN_VAL(desktop->x, EINA_FALSE); 512 EINA_SAFETY_ON_NULL_RETURN_VAL(desktop->x, EINA_FALSE);
489 513
490 return eina_hash_del_by_key(desktop->x, key); 514 eina_lock_take(&_lock);
515 ret = eina_hash_del_by_key(desktop->x, key);
516 eina_lock_release(&_lock);
517 return ret;
491} 518}
492 519
493EAPI void * 520EAPI void *