From: Jaroslav Kysela Date: Fri, 4 Mar 2016 08:57:33 +0000 (+0100) Subject: use tvh_mutex_timedlock instead pthread_mutex_timedlock X-Git-Tag: v4.2.1~966 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cfe0b1b3c17c4ca5b5af10b8b97b023ea1a17047;p=thirdparty%2Ftvheadend.git use tvh_mutex_timedlock instead pthread_mutex_timedlock --- diff --git a/src/input/mpegts/mpegts_mux.c b/src/input/mpegts/mpegts_mux.c index 834718243..d3c98080a 100644 --- a/src/input/mpegts/mpegts_mux.c +++ b/src/input/mpegts/mpegts_mux.c @@ -1341,12 +1341,8 @@ mpegts_mux_tuning_error ( const char *mux_uuid, mpegts_mux_instance_t *mmi_match { mpegts_mux_t *mm; mpegts_mux_instance_t *mmi; - struct timespec timeout; - timeout.tv_sec = 2; - timeout.tv_nsec = 0; - - if (!pthread_mutex_timedlock(&global_lock, &timeout)) { + if (!tvh_mutex_timedlock(&global_lock, 2000000)) { mm = mpegts_mux_find(mux_uuid); if (mm) { if ((mmi = mm->mm_active) != NULL && mmi == mmi_match) diff --git a/src/tvheadend.h b/src/tvheadend.h index c739b2e68..7e4e0d6ea 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -687,6 +687,8 @@ int tvhthread_create int tvhtread_renice(int value); +int tvh_mutex_timedlock(pthread_mutex_t *mutex, int64_t usec); + int tvh_open(const char *pathname, int flags, mode_t mode); int tvh_socket(int domain, int type, int protocol); diff --git a/src/wrappers.c b/src/wrappers.c index 60feb5918..c94b07cf2 100644 --- a/src/wrappers.c +++ b/src/wrappers.c @@ -18,32 +18,22 @@ #include #endif -#if ENABLE_ANDROID int -pthread_mutex_timedlock - ( pthread_mutex_t *mutex, struct timespec *timeout ) +tvh_mutex_timedlock + ( pthread_mutex_t *mutex, int64_t usec ) { - struct timeval timenow; - struct timespec sleepytime; + int64_t finish = getmonoclock() + usec; int retcode; - /* This is just to avoid a completely busy wait */ - sleepytime.tv_sec = 0; - sleepytime.tv_nsec = 10000000; /* 10ms */ - while ((retcode = pthread_mutex_trylock (mutex)) == EBUSY) { - gettimeofday (&timenow, NULL); - - if (timenow.tv_sec >= timeout->tv_sec && - (timenow.tv_usec * 1000) >= timeout->tv_nsec) + if (getmonoclock() >= finish) return ETIMEDOUT; - nanosleep (&sleepytime, NULL); + usleep(10000); } return retcode; } -#endif int tvh_open(const char *pathname, int flags, mode_t mode)