Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use tvh_mutex_timedlock instead pthread_mutex_timedlock
  • Loading branch information
perexg committed Mar 4, 2016
1 parent 055be40 commit cfe0b1b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
6 changes: 1 addition & 5 deletions src/input/mpegts/mpegts_mux.c
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/tvheadend.h
Expand Up @@ -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);
Expand Down
20 changes: 5 additions & 15 deletions src/wrappers.c
Expand Up @@ -18,32 +18,22 @@
#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)
Expand Down

0 comments on commit cfe0b1b

Please sign in to comment.