[vlc-devel] [PATCH v2 9/9] android: fix monotonic cond_timedwait on newer versions

Thomas Guillem tom at gllm.fr
Thu Oct 9 19:50:44 CEST 2014



On Thu, Oct 9, 2014, at 18:59, Rémi Denis-Courmont wrote:
> Le jeudi 9 octobre 2014, 18:45:27 Thomas Guillem a écrit :
> > diff --git a/src/android/thread.c b/src/android/thread.c
> > index 1553073..5a6611e 100644
> > --- a/src/android/thread.c
> > +++ b/src/android/thread.c
> > @@ -185,8 +185,18 @@ void vlc_threads_setup (libvlc_int_t *p_libvlc)
> > 
> >  void vlc_cond_init (vlc_cond_t *condvar)
> >  {
> > +#ifdef HAVE_PTHREAD_CONDATTR_SETCLOCK
> > +    pthread_condattr_t attr;
> > +
> > +    pthread_condattr_init (&attr);
> > +    pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
> > +
> > +    if (unlikely(pthread_cond_init (&condvar->cond, &attr)))
> > +        abort ();
> > +#else
> >      if (unlikely(pthread_cond_init (&condvar->cond, NULL)))
> >          abort ();
> > +#endif
> >      condvar->clock = CLOCK_MONOTONIC;
> >  }
> > 
> > @@ -257,7 +267,10 @@ int vlc_cond_timedwait (vlc_cond_t *condvar,
> > vlc_mutex_t *p_mutex, {
> >      struct timespec ts = mtime_to_ts (deadline);
> >      vlc_thread_t th = thread;
> > +    int val;
> > +#ifdef HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP
> >      int (*cb)(pthread_cond_t *, pthread_mutex_t *, const struct timespec
> > *); +#endif
> > 
> >      if (th != NULL)
> >      {
> > @@ -277,6 +290,7 @@ int vlc_cond_timedwait (vlc_cond_t *condvar, vlc_mutex_t
> > *p_mutex, }
> >      }
> > 
> > +#if defined (HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP)
> >      switch (condvar->clock)
> >      {
> >           case CLOCK_REALTIME:
> > @@ -288,8 +302,13 @@ int vlc_cond_timedwait (vlc_cond_t *condvar,
> > vlc_mutex_t *p_mutex, default:
> >               assert (0);
> >      }
> > +    val = cb (&condvar->cond, p_mutex, &ts);
> > +#elif defined (HAVE_PTHREAD_CONDATTR_SETCLOCK)
> > +    val = pthread_cond_timedwait(&condvar->cond, p_mutex, &ts);
> > +#else
> > +    assert (0);
> > +#endif
> 
> The CPP logic here seems incoherent with that in vlc_cond_init().

Yes I see, I'll fix it.
Maybe it's better to throw a build error instead of an assert in case of
#else. No ?

> 
> > 
> > -    int val = cb (&condvar->cond, p_mutex, &ts);
> >      if (val != ETIMEDOUT)
> >          VLC_THREAD_ASSERT ("timed-waiting on condition");
> 
> -- 
> Rémi Denis-Courmont
> http://www.remlab.net/
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



More information about the vlc-devel mailing list