]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
use tvh_mutex_timedlock instead pthread_mutex_timedlock
authorJaroslav Kysela <perex@perex.cz>
Fri, 4 Mar 2016 08:57:33 +0000 (09:57 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 4 Mar 2016 08:57:33 +0000 (09:57 +0100)
src/input/mpegts/mpegts_mux.c
src/tvheadend.h
src/wrappers.c

index 83471824399f3f50d8bb19ec320777f1bbae6540..d3c98080a03d9a0180ac436eabfd3e5de0dae535 100644 (file)
@@ -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)
index c739b2e6825807e7f0d1a92a8bf589d82aff1950..7e4e0d6ea9d7c84752eccb1809914f1e23e48a26 100644 (file)
@@ -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);
index 60feb5918c9a1ef500e1e9070dbb5b7d57acc966..c94b07cf26b8bb87aaf17ac8eefc2d21edb7b595 100644 (file)
 #include <pthread_np.h>
 #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)