summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean.guyomarch@openwide.fr>2016-08-26 17:41:20 +0200
committerJean Guyomarc'h <jean@guyomarch.bzh>2016-08-26 21:16:39 +0200
commit5db3357f4029ad88b14ceb7b125d981e23889ec8 (patch)
tree722d67e2eb27dd2bdf7de4ebb700510f23d565ee
parentaaa0e962b75174b6dca90816b11a4e05c2985a9e (diff)
eina: overhaul Mac OS X semaphores
Mac OS X does not support POSIX unnamed semaphores, only named semaphores, which are persistant IPC: when the program exits, and if semaphores where not released, they stay forever... All EFL programs were "leaking" a semaphore, due to how eina_log_monitor manages its resources. Therefore, after building EFL a lot (which run eolian_gen, eolian_cxx, elua, edje_cc, ...) we were not able to create any semaphore... Now, we get rid of these semaphores and use Mac OS X's own semaphores. Code is less cumbersome, and we don't have any disavantage of the named semaphores. Fixes T4423 @fix
-rw-r--r--src/lib/eina/eina_inline_lock_posix.x34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/lib/eina/eina_inline_lock_posix.x b/src/lib/eina/eina_inline_lock_posix.x
index b52a6473bf..d2e4b95952 100644
--- a/src/lib/eina/eina_inline_lock_posix.x
+++ b/src/lib/eina/eina_inline_lock_posix.x
@@ -42,6 +42,10 @@
42# include <libkern/OSAtomic.h> 42# include <libkern/OSAtomic.h>
43#endif 43#endif
44 44
45#ifdef EINA_HAVE_OSX_SEMAPHORE
46# include <mach/mach.h>
47#endif
48
45#include <semaphore.h> 49#include <semaphore.h>
46 50
47#include <sys/time.h> 51#include <sys/time.h>
@@ -94,15 +98,7 @@ typedef Eina_Lock Eina_Spinlock;
94#endif 98#endif
95 99
96#if defined(EINA_HAVE_OSX_SEMAPHORE) 100#if defined(EINA_HAVE_OSX_SEMAPHORE)
97/* OSX supports only named semaphores. 101typedef semaphore_t Eina_Semaphore;
98 * So, we need to be able to generate a unique string identifier for each
99 * semaphore we want to create. */
100struct _Eina_Semaphore
101{
102 sem_t *sema;
103 char name[32];
104};
105typedef struct _Eina_Semaphore Eina_Semaphore;
106#else 102#else
107typedef sem_t Eina_Semaphore; 103typedef sem_t Eina_Semaphore;
108#endif 104#endif
@@ -838,13 +834,10 @@ eina_semaphore_new(Eina_Semaphore *sem, int count_init)
838 return EINA_FALSE; 834 return EINA_FALSE;
839 835
840#if defined(EINA_HAVE_OSX_SEMAPHORE) 836#if defined(EINA_HAVE_OSX_SEMAPHORE)
841 /* Atomic increment to generate the unique identifier */ 837 kern_return_t kr;
842 snprintf(sem->name, sizeof(sem->name), "/eina%x%x%x", 838
843 (unsigned int)getpid(), (unsigned int)rand(), (unsigned int)rand()); 839 kr = semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, count_init);
844 sem->name[sizeof(sem->name) - 1] = '\0'; 840 return (kr == KERN_SUCCESS) ? EINA_TRUE : EINA_FALSE;
845 sem_unlink(sem->name);
846 sem->sema = sem_open(sem->name, O_CREAT | O_EXCL, 0600, count_init);
847 return (sem->sema == SEM_FAILED) ? EINA_FALSE : EINA_TRUE;
848#else 841#else
849 return (sem_init(sem, 0, count_init) == 0) ? EINA_TRUE : EINA_FALSE; 842 return (sem_init(sem, 0, count_init) == 0) ? EINA_TRUE : EINA_FALSE;
850#endif 843#endif
@@ -857,9 +850,8 @@ eina_semaphore_free(Eina_Semaphore *sem)
857 return EINA_FALSE; 850 return EINA_FALSE;
858 851
859#if defined(EINA_HAVE_OSX_SEMAPHORE) 852#if defined(EINA_HAVE_OSX_SEMAPHORE)
860 const int closed = sem_close(sem->sema); 853 return (semaphore_destroy(*sem, mach_task_self()) == KERN_SUCCESS)
861 const int unlinked = sem_unlink(sem->name); 854 ? EINA_TRUE : EINA_FALSE;
862 return ((closed == 0) && (unlinked == 0)) ? EINA_TRUE : EINA_FALSE;
863#else 855#else
864 return (sem_destroy(sem) == 0) ? EINA_TRUE : EINA_FALSE; 856 return (sem_destroy(sem) == 0) ? EINA_TRUE : EINA_FALSE;
865#endif 857#endif
@@ -877,7 +869,7 @@ eina_semaphore_lock(Eina_Semaphore *sem)
877 { 869 {
878 if ( 870 if (
879#if defined(EINA_HAVE_OSX_SEMAPHORE) 871#if defined(EINA_HAVE_OSX_SEMAPHORE)
880 sem_wait(sem->sema) 872 semaphore_wait(*sem)
881#else 873#else
882 sem_wait(sem) 874 sem_wait(sem)
883#endif 875#endif
@@ -906,7 +898,7 @@ eina_semaphore_release(Eina_Semaphore *sem, int count_release EINA_UNUSED)
906 return EINA_FALSE; 898 return EINA_FALSE;
907 899
908#if defined(EINA_HAVE_OSX_SEMAPHORE) 900#if defined(EINA_HAVE_OSX_SEMAPHORE)
909 return (sem_post(sem->sema) == 0) ? EINA_TRUE : EINA_FALSE; 901 return (semaphore_signal(*sem) == KERN_SUCCESS) ? EINA_TRUE : EINA_FALSE;
910#else 902#else
911 return (sem_post(sem) == 0) ? EINA_TRUE : EINA_FALSE; 903 return (sem_post(sem) == 0) ? EINA_TRUE : EINA_FALSE;
912#endif 904#endif