[vlc-devel] [PATCH] Android: remove polling timer in mwait() and msleep()

Rémi Denis-Courmont remi at remlab.net
Tue Oct 16 18:06:30 CEST 2012


Le mardi 16 octobre 2012 18:57:29, Rafaël Carré a écrit :
> Hello,
> 
> Seems to work, but I prefer to test it a bit more
> 
> Le 16/10/2012 17:26, Rémi Denis-Courmont a écrit :
> > Le mardi 16 octobre 2012 18:24:37, Rémi Denis-Courmont a écrit :
> >> ---
> >> 
> >>  src/android/thread.c |   37 ++++++++++++++-----------------------
> >>  1 file changed, 14 insertions(+), 23 deletions(-)
> >> 
> >> diff --git a/src/android/thread.c b/src/android/thread.c
> >> index 10380cb..c021af6 100644
> >> --- a/src/android/thread.c
> >> +++ b/src/android/thread.c
> >> @@ -494,34 +494,25 @@ mtime_t mdate (void)
> >> 
> >>  #undef mwait
> >>  void mwait (mtime_t deadline)
> >>  {
> >> 
> >> -    deadline -= mdate ();
> >> -    if (deadline > 0)
> >> -        msleep (deadline);
> >> +    vlc_mutex_t lock;
> >> +    vlc_cond_t wait;
> >> +
> >> +    vlc_mutex_init (&lock);
> >> +    vlc_cond_init (&wait);
> >> +
> >> +    vlc_mutex_lock (&lock);
> >> +    mutex_cleanup_push (&lock);
> >> +    while (!vlc_cond_timedwait (&wait, &lock, deadline));
> >> +    vlc_cleanup_run ();
> >> +
> >> +    vlc_cond_destroy (&wait);
> >> +    vlc_mutex_destroy (&lock);
> > 
> > Strictly speaking the mutex and condition variable are leaked upon
> > cancellation, though.
> 
> vlc_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; would remove need for
> vlc_mutex_init / vlc_mutex_destroy no ?

On Android, and more generally on Linux/NPTH, destroying a mutex or a 
condition variable does nothing other than sanity checks.
I don't really care.

But then, why do you not do the same in vlc_mutex_init()?

> Can vlc_cleanup_push calls can be nested ?

Of course, it's a stack as hinted by the push & pop names.

-- 
Rémi Denis-Courmont
http://www.remlab.net/



More information about the vlc-devel mailing list