From: cedric Date: Mon, 30 May 2011 15:24:06 +0000 (+0000) Subject: eina: add eina_condition_timedwait. X-Git-Tag: 2.0_alpha~70^2~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d112457f80127da8d3bf6574e96cda4645641904;p=framework%2Fuifw%2Feina.git eina: add eina_condition_timedwait. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@59819 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/ChangeLog b/ChangeLog index 79cbe7a..093de19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -93,3 +93,7 @@ 2011-05-24 Cedric Bail * Add eina_inlist_sorted_insert. + +2011-05-30 Cedric Bail + + * Add eina_condition_timedwait. diff --git a/src/include/eina_inline_lock_posix.x b/src/include/eina_inline_lock_posix.x index 4c111ed..c1026d4 100644 --- a/src/include/eina_inline_lock_posix.x +++ b/src/include/eina_inline_lock_posix.x @@ -310,7 +310,27 @@ eina_condition_wait(Eina_Condition *cond) assert(cond->lock != NULL); #endif - return pthread_cond_wait(&(cond->condition), &(cond->lock->mutex)) == 0 ? EINA_TRUE : EINA_FALSE; + return pthread_cond_wait(&(cond->condition), + &(cond->lock->mutex)) == 0 ? EINA_TRUE : EINA_FALSE; +} + +static inline Eina_Bool +eina_condition_timedwait(Eina_Condition *cond, double t) +{ + struct timespec tv; + +#ifdef EINA_HAVE_DEBUG_THREADS + assert(_eina_threads_activated); + assert(cond->lock != NULL); +#endif + + tv.tv_sec = t; + tv.tv_nsec = (t - (double) tv.tv_sec) * 1000000000; + + return pthread_cond_timedwait(&(cond->condition), + &(cond->lock->mutex), + &tv) == 0 ? + EINA_TRUE : EINA_FALSE; } static inline Eina_Bool diff --git a/src/include/eina_inline_lock_void.x b/src/include/eina_inline_lock_void.x index aae3ee1..0d0c398 100644 --- a/src/include/eina_inline_lock_void.x +++ b/src/include/eina_inline_lock_void.x @@ -156,6 +156,12 @@ eina_condition_wait(Eina_Condition *cond EINA_UNUSED) } static inline Eina_Bool +eina_condition_timedwait(Eina_Condition *cond EINA_UNUSED, double val) +{ + return EINA_FALSE; +} + +static inline Eina_Bool eina_condition_broadcast(Eina_Condition *cond EINA_UNUSED) { return EINA_FALSE; diff --git a/src/include/eina_inline_lock_win32.x b/src/include/eina_inline_lock_win32.x index f242c2f..6b96479 100644 --- a/src/include/eina_inline_lock_win32.x +++ b/src/include/eina_inline_lock_win32.x @@ -144,7 +144,7 @@ eina_condition_free(Eina_Condition *cond) } static inline Eina_Bool -eina_condition_wait(Eina_Condition *cond) +_eina_condition_internal_timedwait(Eina_Condition *cond, DWORD t) { #if _WIN32_WINNT >= 0x0600 SleepConditionVariableCS(&cond->condition, cond->mutex, INFINITE); @@ -162,7 +162,7 @@ eina_condition_wait(Eina_Condition *cond) * semaphore until or * are called by another thread. */ - ret = SignalObjectAndWait(cond->mutex, cond->semaphore, INFINITE, FALSE); + ret = SignalObjectAndWait(cond->mutex, cond->semaphore, t, FALSE); if (ret == WAIT_FAILED) return EINA_FALSE; @@ -187,7 +187,7 @@ eina_condition_wait(Eina_Condition *cond) * This call atomically signals the event and waits until * it can acquire the . This is required to ensure fairness. */ - ret = SignalObjectAndWait(cond->waiters_done, cond->mutex, INFINITE, FALSE); + ret = SignalObjectAndWait(cond->waiters_done, cond->mutex, t, FALSE); if (ret == WAIT_FAILED) return EINA_FALSE; } @@ -197,7 +197,7 @@ eina_condition_wait(Eina_Condition *cond) * Always regain the external mutex since that's the guarantee we * give to our callers. */ - ret = WaitForSingleObject(cond->mutex, INFINITE); + ret = WaitForSingleObject(cond->mutex, t); if (ret == WAIT_FAILED) return EINA_FALSE; } @@ -207,6 +207,18 @@ eina_condition_wait(Eina_Condition *cond) } static inline Eina_Bool +eina_condition_timedwait(Eina_Condition *cond, double val) +{ + _eina_condition_internal_timedwait(cond, val * 1000); +} + +static inline Eina_Bool +eina_condition_wait(Eina_Condition *cond) +{ + _eina_condition_internal_timedwait(cond, INFINITE); +} + +static inline Eina_Bool eina_condition_broadcast(Eina_Condition *cond) { #if _WIN32_WINNT >= 0x0600 diff --git a/src/include/eina_inline_lock_wince.x b/src/include/eina_inline_lock_wince.x index 475c4d6..65145be 100644 --- a/src/include/eina_inline_lock_wince.x +++ b/src/include/eina_inline_lock_wince.x @@ -96,6 +96,12 @@ eina_condition_wait(Eina_Condition *cond) } static inline Eina_Bool +eina_condition_timedwait(Eina_Condition *cond, double t) +{ + return EINA_FALSE; +} + +static inline Eina_Bool eina_condition_broadcast(Eina_Condition *cond) { return EINA_FALSE; diff --git a/src/include/eina_lock.h b/src/include/eina_lock.h index c6f6c74..2dbeaba 100644 --- a/src/include/eina_lock.h +++ b/src/include/eina_lock.h @@ -63,6 +63,7 @@ static inline void eina_lock_debug(const Eina_Lock *mutex); static inline Eina_Bool eina_condition_new(Eina_Condition *cond, Eina_Lock *mutex); static inline void eina_condition_free(Eina_Condition *cond); static inline Eina_Bool eina_condition_wait(Eina_Condition *cond); +static inline Eina_Bool eina_condition_timedwait(Eina_Condition *cond, double t); static inline Eina_Bool eina_condition_broadcast(Eina_Condition *cond); static inline Eina_Bool eina_condition_signal(Eina_Condition *cond);