summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean.guyomarch@openwide.fr>2016-08-26 17:41:20 +0200
committerStefan Schmidt <stefan@osg.samsung.com>2016-09-15 11:36:06 +0200
commit87282bd91ca351a7da70933eb71624cf9f272567 (patch)
tree06f19052d6ca5835124f952d168ad721a3c063e7
parent67c9e9c9608e9564ee4c09787e50f5a17b87c2c3 (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 f8110d82fd..292bce5b5a 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>
@@ -92,15 +96,7 @@ typedef Eina_Lock Eina_Spinlock;
92#endif 96#endif
93 97
94#if defined(EINA_HAVE_OSX_SEMAPHORE) 98#if defined(EINA_HAVE_OSX_SEMAPHORE)
95/* OSX supports only named semaphores. 99typedef semaphore_t Eina_Semaphore;
96 * So, we need to be able to generate a unique string identifier for each
97 * semaphore we want to create. */
98struct _Eina_Semaphore
99{
100 sem_t *sema;
101 char name[32];
102};
103typedef struct _Eina_Semaphore Eina_Semaphore;
104#else 100#else
105typedef sem_t Eina_Semaphore; 101typedef sem_t Eina_Semaphore;
106#endif 102#endif
@@ -830,13 +826,10 @@ eina_semaphore_new(Eina_Semaphore *sem, int count_init)
830 return EINA_FALSE; 826 return EINA_FALSE;
831 827
832#if defined(EINA_HAVE_OSX_SEMAPHORE) 828#if defined(EINA_HAVE_OSX_SEMAPHORE)
833 /* Atomic increment to generate the unique identifier */ 829 kern_return_t kr;
834 snprintf(sem->name, sizeof(sem->name), "/eina%x%x%x", 830
835 (unsigned int)getpid(), (unsigned int)rand(), (unsigned int)rand()); 831 kr = semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, count_init);
836 sem->name[sizeof(sem->name) - 1] = '\0'; 832 return (kr == KERN_SUCCESS) ? EINA_TRUE : EINA_FALSE;
837 sem_unlink(sem->name);
838 sem->sema = sem_open(sem->name, O_CREAT | O_EXCL, 0600, count_init);
839 return (sem->sema == SEM_FAILED) ? EINA_FALSE : EINA_TRUE;
840#else 833#else
841 return (sem_init(sem, 0, count_init) == 0) ? EINA_TRUE : EINA_FALSE; 834 return (sem_init(sem, 0, count_init) == 0) ? EINA_TRUE : EINA_FALSE;
842#endif 835#endif
@@ -849,9 +842,8 @@ eina_semaphore_free(Eina_Semaphore *sem)
849 return EINA_FALSE; 842 return EINA_FALSE;
850 843
851#if defined(EINA_HAVE_OSX_SEMAPHORE) 844#if defined(EINA_HAVE_OSX_SEMAPHORE)
852 const int closed = sem_close(sem->sema); 845 return (semaphore_destroy(*sem, mach_task_self()) == KERN_SUCCESS)
853 const int unlinked = sem_unlink(sem->name); 846 ? EINA_TRUE : EINA_FALSE;
854 return ((closed == 0) && (unlinked == 0)) ? EINA_TRUE : EINA_FALSE;
855#else 847#else
856 return (sem_destroy(sem) == 0) ? EINA_TRUE : EINA_FALSE; 848 return (sem_destroy(sem) == 0) ? EINA_TRUE : EINA_FALSE;
857#endif 849#endif
@@ -869,7 +861,7 @@ eina_semaphore_lock(Eina_Semaphore *sem)
869 { 861 {
870 if ( 862 if (
871#if defined(EINA_HAVE_OSX_SEMAPHORE) 863#if defined(EINA_HAVE_OSX_SEMAPHORE)
872 sem_wait(sem->sema) 864 semaphore_wait(*sem)
873#else 865#else
874 sem_wait(sem) 866 sem_wait(sem)
875#endif 867#endif
@@ -898,7 +890,7 @@ eina_semaphore_release(Eina_Semaphore *sem, int count_release EINA_UNUSED)
898 return EINA_FALSE; 890 return EINA_FALSE;
899 891
900#if defined(EINA_HAVE_OSX_SEMAPHORE) 892#if defined(EINA_HAVE_OSX_SEMAPHORE)
901 return (sem_post(sem->sema) == 0) ? EINA_TRUE : EINA_FALSE; 893 return (semaphore_signal(*sem) == KERN_SUCCESS) ? EINA_TRUE : EINA_FALSE;
902#else 894#else
903 return (sem_post(sem) == 0) ? EINA_TRUE : EINA_FALSE; 895 return (sem_post(sem) == 0) ? EINA_TRUE : EINA_FALSE;
904#endif 896#endif