[vlc-devel] [PATCH v2 2/2] os2: implement vlc_once()

Romain Vimont rom1v at videolabs.io
Tue Apr 24 12:35:08 CEST 2018


On Tue, Apr 24, 2018 at 07:06:15PM +0900, KO Myung-Hun wrote:
> Ping ?
> 
> KO Myung-Hun wrote:
> > ---
> >  include/vlc_threads.h |  6 ++++++
> >  src/os2/thread.c      | 18 ++++++++++++++++++
> >  2 files changed, 24 insertions(+)
> > 
> > diff --git a/include/vlc_threads.h b/include/vlc_threads.h
> > index 37054a3ded..b7505da266 100644
> > --- a/include/vlc_threads.h
> > +++ b/include/vlc_threads.h
> > @@ -125,6 +125,12 @@ typedef struct
> >  #define VLC_STATIC_COND { NULLHANDLE, 0, NULLHANDLE, 0 }
> >  #define LIBVLC_NEED_SEMAPHORE
> >  #define LIBVLC_NEED_RWLOCK
> > +typedef struct
> > +{
> > +    unsigned done;

The atomic_load_explicit() argument must point to an atomic type:
<http://en.cppreference.com/w/c/atomic/atomic_load>
<http://en.cppreference.com/w/c/language/atomic>
<https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.cbclx01/atomic_integ.htm>

> > +    vlc_mutex_t mutex;
> > +} vlc_once_t;
> > +#define VLC_STATIC_ONCE { 0, VLC_STATIC_MUTEX }
> >  typedef struct vlc_threadvar *vlc_threadvar_t;
> >  typedef struct vlc_timer *vlc_timer_t;
> >  
> > diff --git a/src/os2/thread.c b/src/os2/thread.c
> > index 3ecf24dc0d..9f64fcc3b3 100644
> > --- a/src/os2/thread.c
> > +++ b/src/os2/thread.c
> > @@ -38,6 +38,7 @@
> >  #include <limits.h>
> >  #include <errno.h>
> >  #include <time.h>
> > +#include <stdatomic.h>
> >  
> >  #include <sys/types.h>
> >  #ifdef HAVE_SYS_SOCKET_H
> > @@ -429,6 +430,23 @@ int vlc_cond_timedwait_daytime (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
> >      return vlc_cond_wait_common (p_condvar, p_mutex, ulTimeout);
> >  }
> >  
> > +void vlc_once(vlc_once_t *once, void (*cb)(void))
> > +{
> > +    if( atomic_load_explicit( &once->done, memory_order_acquire ) == 0 )
> > +    {
> > +        vlc_mutex_lock( &once->mutex );
> > +
> > +        if( atomic_load_explicit( &once->done, memory_order_acquire ) == 0 )
> > +        {
> > +            cb();
> > +
> > +            atomic_store_explicit( &once->done, 1, memory_order_release );
> > +        }
> > +
> > +        vlc_mutex_unlock( &once->mutex );
> > +    }
> > +}

Once "once" (twice?) uses an atomic type, vlc_once() looks good to me.

> > +
> >  /*** Thread-specific variables (TLS) ***/
> >  struct vlc_threadvar
> >  {
> 
> -- 
> KO Myung-Hun
> 
> Using Mozilla SeaMonkey 2.7.2
> Under OS/2 Warp 4 for Korean with FixPak #15
> In VirtualBox v4.1.32 on Intel Core i7-3615QM 2.30GHz with 8GB RAM
> 
> Korean OS/2 User Community : http://www.os2.kr/
> 
> _______________________________________________
> 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