eina: Set EINA_ERROR_TIMEOUT to cond_timedwait
authorJean-Philippe Andre <jp.andre@samsung.com>
Mon, 1 Aug 2016 08:38:05 +0000 (17:38 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Tue, 16 Aug 2016 07:14:21 +0000 (16:14 +0900)
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

src/lib/eina/eina_error.c
src/lib/eina/eina_inline_lock_posix.x
src/lib/eina/eina_lock.h
src/tests/eina/eina_test_lock.c

index e0b70ca..3e47082 100644 (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;
index 8af5158..70375ab 100644 (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
index 482a77e..ed79649 100644 (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.
index d15703c..fb18f3b 100644 (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);