eina: Set EINA_ERROR_TIMEOUT to cond_timedwait

This adds a new error code.

I'm using a weak symbol (were supported, ie GCC on linux) for
some kind of forward compatibility.

Fixes T1780

@feature
This commit is contained in:
Jean-Philippe Andre 2016-08-01 17:38:05 +09:00
parent 67ab4e3b4d
commit cb24d5f489
4 changed files with 22 additions and 3 deletions

View File

@ -110,9 +110,11 @@ _eina_error_msg_alloc(void)
*/
EAPI Eina_Error EINA_ERROR_OUT_OF_MEMORY = 0;
static const char EINA_ERROR_OUT_OF_MEMORY_STR[] = "Out of memory";
EWAPI Eina_Error EINA_ERROR_TIMEOUT = 0;
static const char EINA_ERROR_TIMEOUT_STR[] = "Timed out";
/**
* @endcond
*/
@ -136,6 +138,7 @@ eina_error_init(void)
/* TODO register the eina's basic errors */
EINA_ERROR_OUT_OF_MEMORY = eina_error_msg_static_register(
EINA_ERROR_OUT_OF_MEMORY_STR);
EINA_ERROR_TIMEOUT = eina_error_msg_static_register(EINA_ERROR_TIMEOUT_STR);
if (!eina_tls_new(&_eina_last_key))
return EINA_FALSE;
return EINA_TRUE;

View File

@ -78,6 +78,8 @@ typedef void (*Eina_Lock_Bt_Func) ();
#include <time.h>
#include <sys/time.h>
#include <eina_error.h>
typedef struct _Eina_Lock Eina_Lock;
typedef struct _Eina_RWLock Eina_RWLock;
typedef struct _Eina_Condition Eina_Condition;
@ -514,7 +516,13 @@ eina_condition_timedwait(Eina_Condition *cond, double t)
&(cond->lock->mutex),
&ts);
if (err == 0) r = EINA_TRUE;
else if (err == EPERM || err == ETIMEDOUT) r = EINA_FALSE;
else if (err == EPERM)
err = EINA_FALSE;
else if (err == ETIMEDOUT)
{
r = EINA_FALSE;
if (&EINA_ERROR_TIMEOUT) eina_error_set(EINA_ERROR_TIMEOUT);
}
else EINA_LOCK_ABORT_DEBUG(err, cond_timedwait, cond);
#ifdef EINA_HAVE_DEBUG_THREADS

View File

@ -97,6 +97,12 @@ typedef enum
*/
typedef void (*Eina_TLS_Delete_Cb)(void *ptr);
/**
* @brief Error set when a blocking function timed out.
* @since 1.19
*/
EWAPI extern Eina_Error EINA_ERROR_TIMEOUT;
# include "eina_inline_lock_posix.x"
/**
@ -250,7 +256,8 @@ static inline Eina_Bool eina_condition_wait(Eina_Condition *cond);
* @param[in] cond The #Eina_Condition upon which the thread waits.
* @param[in] t The maximum amount of time to wait, in seconds.
*
* @return #EINA_TRUE on success, #EINA_FALSE otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE otherwise. If the operation
* timed out, eina error will be set to #EINA_ERROR_TIMEOUT.
*
* @details This function makes a thread block until either a signal is sent to it via
* @p cond or @p t seconds have passed.

View File

@ -227,6 +227,7 @@ START_TEST(eina_test_rwlock)
delay = (ts2.tv_sec - ts.tv_sec) * 1000L + (ts2.tv_nsec - ts.tv_nsec) / 1000000L;
fail_if(delay < 50);
fail_if(delay > 200);
fail_if(eina_error_get() != EINA_ERROR_TIMEOUT);
fail_if(eina_lock_release(&mtcond) != EINA_LOCK_SUCCEED);
eina_thread_join(thread);