On Wed, Oct 7, 2015 at 10:48 PM, Luca Barbato <[email protected]> wrote: > --- > libavutil/thread.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > It isn't exactly beautiful with `!control` used to return 0 and > suppress the unused warning, but seems to work as intended and it > is fully portable, I'd use `({ routine(); !control; })` if we assume > the construct is always supported, but I'm afraid it is not. > > diff --git a/libavutil/thread.h b/libavutil/thread.h > index 3556544..d2fb847 100644 > --- a/libavutil/thread.h > +++ b/libavutil/thread.h > @@ -39,6 +39,11 @@ > #define ff_mutex_unlock pthread_mutex_unlock > #define ff_mutex_destroy pthread_mutex_destroy > > +#define AVOnce pthread_once_t > +#define AV_ONCE_INIT PTHREAD_ONCE_INIT > + > +#define ff_thread_once(control, routine) pthread_once(control, routine) > + > #else > > #define AVMutex char > @@ -48,6 +53,11 @@ > #define ff_mutex_unlock(mutex) (0) > #define ff_mutex_destroy(mutex) (0) > > +#define AVOnce char > +#define AV_ONCE_INIT 0 > + > +#define ff_thread_once(control, routine) !control; routine();
You should probably still check if control is still 0, only run routine() then, and set it to 1 after. Multiple runs of the init may be annoying. > + > #endif > > #endif /* AVUTIL_THREAD_H */ > -- > 2.5.0 > > _______________________________________________ > libav-devel mailing list > [email protected] > https://lists.libav.org/mailman/listinfo/libav-devel _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
