mirror of
https://code.videolan.org/videolan/vlc
synced 2024-09-12 13:44:56 +02:00
android: fix monotonic cond_timedwait on newer versions
android-L drops support for pthread_cond_timedwait_monotonic_np and adds support for pthread_condattr_setclock. So, use the good function depending on configure detection. Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
This commit is contained in:
parent
417b6eb0f0
commit
83c56e1b57
@ -541,7 +541,7 @@ need_libc=false
|
|||||||
|
|
||||||
dnl Check for usual libc functions
|
dnl Check for usual libc functions
|
||||||
AC_CHECK_DECLS([nanosleep],,,[#include <time.h>])
|
AC_CHECK_DECLS([nanosleep],,,[#include <time.h>])
|
||||||
AC_CHECK_FUNCS([daemon fcntl fstatvfs fork getenv getpwuid_r isatty lstat memalign mmap openat pread posix_fadvise posix_madvise setlocale stricmp strnicmp strptime uselocale])
|
AC_CHECK_FUNCS([daemon fcntl fstatvfs fork getenv getpwuid_r isatty lstat memalign mmap openat pread posix_fadvise posix_madvise setlocale stricmp strnicmp strptime uselocale pthread_cond_timedwait_monotonic_np pthread_condattr_setclock])
|
||||||
AC_REPLACE_FUNCS([atof atoll dirfd fdopendir flockfile fsync getdelim getpid gmtime_r lldiv localtime_r nrand48 poll posix_memalign rewind setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strsep strtof strtok_r strtoll swab tdestroy strverscmp])
|
AC_REPLACE_FUNCS([atof atoll dirfd fdopendir flockfile fsync getdelim getpid gmtime_r lldiv localtime_r nrand48 poll posix_memalign rewind setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strsep strtof strtok_r strtoll swab tdestroy strverscmp])
|
||||||
AC_CHECK_FUNCS(fdatasync,,
|
AC_CHECK_FUNCS(fdatasync,,
|
||||||
[AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
|
[AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
|
||||||
|
@ -45,6 +45,10 @@
|
|||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <sys/syscall.h> /* __NR_gettid */
|
#include <sys/syscall.h> /* __NR_gettid */
|
||||||
|
|
||||||
|
#if !defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && !defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP)
|
||||||
|
#error no pthread monotonic clock support
|
||||||
|
#endif
|
||||||
|
|
||||||
/* helper */
|
/* helper */
|
||||||
static struct timespec mtime_to_ts (mtime_t date)
|
static struct timespec mtime_to_ts (mtime_t date)
|
||||||
{
|
{
|
||||||
@ -185,8 +189,18 @@ void vlc_threads_setup (libvlc_int_t *p_libvlc)
|
|||||||
|
|
||||||
void vlc_cond_init (vlc_cond_t *condvar)
|
void vlc_cond_init (vlc_cond_t *condvar)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP
|
||||||
if (unlikely(pthread_cond_init (&condvar->cond, NULL)))
|
if (unlikely(pthread_cond_init (&condvar->cond, NULL)))
|
||||||
abort ();
|
abort ();
|
||||||
|
#else
|
||||||
|
pthread_condattr_t attr;
|
||||||
|
|
||||||
|
pthread_condattr_init (&attr);
|
||||||
|
pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
|
||||||
|
|
||||||
|
if (unlikely(pthread_cond_init (&condvar->cond, &attr)))
|
||||||
|
abort ();
|
||||||
|
#endif
|
||||||
condvar->clock = CLOCK_MONOTONIC;
|
condvar->clock = CLOCK_MONOTONIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +271,9 @@ int vlc_cond_timedwait (vlc_cond_t *condvar, vlc_mutex_t *p_mutex,
|
|||||||
{
|
{
|
||||||
struct timespec ts = mtime_to_ts (deadline);
|
struct timespec ts = mtime_to_ts (deadline);
|
||||||
vlc_thread_t th = thread;
|
vlc_thread_t th = thread;
|
||||||
|
#ifdef HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP
|
||||||
int (*cb)(pthread_cond_t *, pthread_mutex_t *, const struct timespec *);
|
int (*cb)(pthread_cond_t *, pthread_mutex_t *, const struct timespec *);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (th != NULL)
|
if (th != NULL)
|
||||||
{
|
{
|
||||||
@ -277,6 +293,7 @@ int vlc_cond_timedwait (vlc_cond_t *condvar, vlc_mutex_t *p_mutex,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP
|
||||||
switch (condvar->clock)
|
switch (condvar->clock)
|
||||||
{
|
{
|
||||||
case CLOCK_REALTIME:
|
case CLOCK_REALTIME:
|
||||||
@ -290,6 +307,10 @@ int vlc_cond_timedwait (vlc_cond_t *condvar, vlc_mutex_t *p_mutex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int val = cb (&condvar->cond, p_mutex, &ts);
|
int val = cb (&condvar->cond, p_mutex, &ts);
|
||||||
|
#else
|
||||||
|
int val = pthread_cond_timedwait(&condvar->cond, p_mutex, &ts);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (val != ETIMEDOUT)
|
if (val != ETIMEDOUT)
|
||||||
VLC_THREAD_ASSERT ("timed-waiting on condition");
|
VLC_THREAD_ASSERT ("timed-waiting on condition");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user