cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=6fd31ab5521e082a09c60183bad0788c98d4c776

commit 6fd31ab5521e082a09c60183bad0788c98d4c776
Author: pierre lamot <pierre.la...@openwide.fr>
Date:   Wed Jan 21 11:05:41 2015 +0100

    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 <ced...@osg.samsung.com>
---
 src/lib/eina/eina_inline_lock_posix.x | 7 ++++---
 src/lib/eina/eina_lock.h              | 7 +------
 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 18732f6e..86e65ef 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)
 static inline Eina_Bool
 eina_semaphore_new(Eina_Semaphore *sem, int count_init)
 {
-   if (!sem || (count_init <= 0))
+   if (!sem || (count_init < 0))
      return EINA_FALSE;
 
 #if defined(EINA_HAVE_OSX_SEMAPHORE)
@@ -759,10 +759,11 @@ eina_semaphore_new(Eina_Semaphore *sem, int count_init)
    eina_spinlock_release(&_sem_ctr_lock);
 
    snprintf(sem->name, sizeof(sem->name), "/eina_sem_%u", _sem_ctr);
-   sem->sema = sem_open(sem->name, O_CREAT, 0644, 1);
+   sem_unlink(sem->name);
+   sem->sema = sem_open(sem->name, O_CREAT, 0644, count_init);
    return (sem->sema == SEM_FAILED) ? EINA_FALSE : EINA_TRUE;
 #else
-   return (sem_init(sem, count_init, 1) == 0) ? EINA_TRUE : EINA_FALSE;
+   return (sem_init(sem, 1, count_init) == 0) ? EINA_TRUE : EINA_FALSE;
 #endif
 }
 
diff --git a/src/lib/eina/eina_lock.h b/src/lib/eina/eina_lock.h
index e77d641..7598869 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);
  * @brief Initializes a new #Eina_Semaphore
  *
  * @param[in] sem The #Eina_Semaphore to be initialized.
- * @param[in] count_init Behavior is platofrm specific. See above.
+ * @param[in] count_init Indicates the initial count of threads waiting on 
this semaphore.
  *
  * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
  *
  * @details This function initializes an unnamed #Eina_Semaphore with 
appropriate values.
  *          These values are platform dependent.
  *
- * @note Be aware that the behavior of the parameter @p count_init differs by
- *       platform. *
- * @li POSIX:  Indicates whether this semaphore can be shared by between 
processes. Greater than 0 == shared.
- * @li Win32:  Indicates the initial count of threads waiting on this 
semaphore.
- *
  * @note Semaphores are not avialable on the WinCE platform.
  *
  * @see eina_semaphore_free()

-- 


Reply via email to