summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpierre lamot <pierre.lamot@openwide.fr>2015-01-21 11:05:41 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-02-05 16:38:06 +0100
commit6fd31ab5521e082a09c60183bad0788c98d4c776 (patch)
treeb7c4e4e06b8db70cbf820cf5a7171608e5cf4911
parent17e73dca0560013ce00277c8cf399461b26442b9 (diff)
eina: fix semaphore initialisation
This patch fix the semaphore initialisation on posix plateform there was a preconditon test which returned the semaphore uninitialised when count_init was 1, this caused the semaphore to be unusable on OSX plateform. Furthermore, it seems that we need to unlink the semaphore before its initialisation on OSX as there seems to have some kind of persistence of the semaphore accross execution. warning, this patch change the signification of the parametter count_init on linux plateform, this parametter is now consistent on every plateform, with the meaning of setting the initial count value of the semaphore. This used to be on linux 1 -> the semaphore is shared and initialised at 1 and 0 -> the semaphore is not initialised, thus, by side effect not shared and initialised at 0. This patch set on linux plateform the semaphore as systematically shared @fix Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/lib/eina/eina_inline_lock_posix.x7
-rw-r--r--src/lib/eina/eina_lock.h7
2 files changed, 5 insertions, 9 deletions
diff --git a/src/lib/eina/eina_inline_lock_posix.x b/src/lib/eina/eina_inline_lock_posix.x
index 18732f6e03..86e65ef4ba 100644
--- a/src/lib/eina/eina_inline_lock_posix.x
+++ b/src/lib/eina/eina_inline_lock_posix.x
@@ -749,7 +749,7 @@ eina_spinlock_free(Eina_Spinlock *spinlock)
749static inline Eina_Bool 749static inline Eina_Bool
750eina_semaphore_new(Eina_Semaphore *sem, int count_init) 750eina_semaphore_new(Eina_Semaphore *sem, int count_init)
751{ 751{
752 if (!sem || (count_init <= 0)) 752 if (!sem || (count_init < 0))
753 return EINA_FALSE; 753 return EINA_FALSE;
754 754
755#if defined(EINA_HAVE_OSX_SEMAPHORE) 755#if defined(EINA_HAVE_OSX_SEMAPHORE)
@@ -759,10 +759,11 @@ eina_semaphore_new(Eina_Semaphore *sem, int count_init)
759 eina_spinlock_release(&_sem_ctr_lock); 759 eina_spinlock_release(&_sem_ctr_lock);
760 760
761 snprintf(sem->name, sizeof(sem->name), "/eina_sem_%u", _sem_ctr); 761 snprintf(sem->name, sizeof(sem->name), "/eina_sem_%u", _sem_ctr);
762 sem->sema = sem_open(sem->name, O_CREAT, 0644, 1); 762 sem_unlink(sem->name);
763 sem->sema = sem_open(sem->name, O_CREAT, 0644, count_init);
763 return (sem->sema == SEM_FAILED) ? EINA_FALSE : EINA_TRUE; 764 return (sem->sema == SEM_FAILED) ? EINA_FALSE : EINA_TRUE;
764#else 765#else
765 return (sem_init(sem, count_init, 1) == 0) ? EINA_TRUE : EINA_FALSE; 766 return (sem_init(sem, 1, count_init) == 0) ? EINA_TRUE : EINA_FALSE;
766#endif 767#endif
767} 768}
768 769
diff --git a/src/lib/eina/eina_lock.h b/src/lib/eina/eina_lock.h
index e77d641b36..7598869193 100644
--- a/src/lib/eina/eina_lock.h
+++ b/src/lib/eina/eina_lock.h
@@ -456,18 +456,13 @@ static inline Eina_Bool eina_tls_set(Eina_TLS key, const void *data);
456 * @brief Initializes a new #Eina_Semaphore 456 * @brief Initializes a new #Eina_Semaphore
457 * 457 *
458 * @param[in] sem The #Eina_Semaphore to be initialized. 458 * @param[in] sem The #Eina_Semaphore to be initialized.
459 * @param[in] count_init Behavior is platofrm specific. See above. 459 * @param[in] count_init Indicates the initial count of threads waiting on this semaphore.
460 * 460 *
461 * @return #EINA_TRUE on success, #EINA_FALSE otherwise. 461 * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
462 * 462 *
463 * @details This function initializes an unnamed #Eina_Semaphore with appropriate values. 463 * @details This function initializes an unnamed #Eina_Semaphore with appropriate values.
464 * These values are platform dependent. 464 * These values are platform dependent.
465 * 465 *
466 * @note Be aware that the behavior of the parameter @p count_init differs by
467 * platform. *
468 * @li POSIX: Indicates whether this semaphore can be shared by between processes. Greater than 0 == shared.
469 * @li Win32: Indicates the initial count of threads waiting on this semaphore.
470 *
471 * @note Semaphores are not avialable on the WinCE platform. 466 * @note Semaphores are not avialable on the WinCE platform.
472 * 467 *
473 * @see eina_semaphore_free() 468 * @see eina_semaphore_free()