Add a new tpl_gthread API to use g_cond_wait_until. 91/254791/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Wed, 3 Mar 2021 02:21:31 +0000 (11:21 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Tue, 9 Mar 2021 08:52:57 +0000 (17:52 +0900)
Change-Id: I7187b036fa58cbe7182659b015a3cb0d5eb56966
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_utils_gthread.c
src/tpl_utils_gthread.h

index 95a1665..65a1db2 100644 (file)
@@ -410,6 +410,18 @@ tpl_gcond_wait(tpl_gcond *gcond, tpl_gmutex *gmutex)
        g_cond_wait(gcond, gmutex);
 }
 
+tpl_result_t
+tpl_cond_timed_wait(tpl_gcond *gcond, tpl_gmutex *gmutex,
+                                       int64_t timeout_ms)
+{
+       gint64 end_time = g_get_monotonic_time() +
+                                               (timeout_ms * G_TIME_SPAN_MILLISECOND);
+       if (!g_cond_wait_until(gcond, gmutex, end_time))
+               return TPL_ERROR_TIME_OUT;
+
+       return TPL_ERROR_NONE;
+}
+
 void
 tpl_gcond_signal(tpl_gcond *gcond)
 {
index 8c0d066..a1d4ce1 100644 (file)
@@ -154,7 +154,7 @@ tpl_gmutex_unlock(tpl_gmutex *gmutex);
 /**
  * wrapping g_cond_init()
  *
- * @param gmutex Pointer to tpl_gcond.
+ * @param gcond Pointer to tpl_gcond.
  */
 void
 tpl_gcond_init(tpl_gcond *gcond);
@@ -162,7 +162,7 @@ tpl_gcond_init(tpl_gcond *gcond);
 /**
  * wrapping g_cond_clear()
  *
- * @param gmutex Pointer to tpl_gcond.
+ * @param gcond Pointer to tpl_gcond.
  */
 void
 tpl_gcond_clear(tpl_gcond *gcond);
@@ -170,12 +170,25 @@ tpl_gcond_clear(tpl_gcond *gcond);
 /**
  * wrapping g_cond_wait()
  *
- * @param gmutex Pointer to tpl_gcond.
+ * @param gcond Pointer to tpl_gcond.
+ * @param gmutex Pointer to tpl_gmutex
  */
 void
 tpl_gcond_wait(tpl_gcond *gcond, tpl_gmutex *gmutex);
 
 /**
+ * wrapping g_cond_wait_until()
+ *
+ * @param gcond Pointer to tpl_gcond.
+ * @param gmutex Pointer to tpl_gmutex.
+ * @param timeout_ms int64_t time(ms) to wait.
+ *
+ * @return tpl_result_t TPL_ERROR_NONE or TPL_ERROR_TIME_OUT
+ */
+tpl_result_t
+tpl_cond_timed_wait(tpl_gcond *gcond, tpl_gmutex *gmutex, int64_t timeout_ms);
+
+/**
  * wrapping g_cond_signal()
  *
  * @param gmutex Pointer to tpl_gcond.