From: Joonbum Ko Date: Wed, 3 Mar 2021 02:21:31 +0000 (+0900) Subject: Add a new tpl_gthread API to use g_cond_wait_until. X-Git-Tag: submit/tizen/20210316.021228~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a7f4ebadd50667726c24a8327c4d2339427b922c;p=platform%2Fcore%2Fuifw%2Flibtpl-egl.git Add a new tpl_gthread API to use g_cond_wait_until. Change-Id: I7187b036fa58cbe7182659b015a3cb0d5eb56966 Signed-off-by: Joonbum Ko --- diff --git a/src/tpl_utils_gthread.c b/src/tpl_utils_gthread.c index 95a1665..65a1db2 100644 --- a/src/tpl_utils_gthread.c +++ b/src/tpl_utils_gthread.c @@ -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) { diff --git a/src/tpl_utils_gthread.h b/src/tpl_utils_gthread.h index 8c0d066..a1d4ce1 100644 --- a/src/tpl_utils_gthread.h +++ b/src/tpl_utils_gthread.h @@ -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,11 +170,24 @@ 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() *