[FFmpeg-devel] [PATCH] avcodec/utils: use a default lock manager that uses a spinlock

Michael Niedermayer michaelni at gmx.at
Thu Oct 17 18:08:37 CEST 2013


On Thu, Oct 17, 2013 at 01:48:05PM +0000, Paul B Mahol wrote:
> On 10/17/13, Michael Niedermayer <michaelni at gmx.at> wrote:
> > That makes avformat & avcodec thread safe without the need to explicitly
> > register a lock manager.
> >
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> >  libavcodec/utils.c |   26 +++++++++++++++++++++++++-
> >  1 file changed, 25 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> > index 3832b81..cf7be5e 100644
> > --- a/libavcodec/utils.c
> > +++ b/libavcodec/utils.c
> > @@ -56,9 +56,33 @@
> >  # include <iconv.h>
> >  #endif
> >
> > +static int default_lockmgr_cb(void **mutex, enum AVLockOp op)
> > +{
> > +    void * volatile *state = mutex;
> > +
> > +    switch (op) {
> > +    case AV_LOCK_CREATE:
> > +        *state = NULL;
> > +        return 0;
> > +    case AV_LOCK_OBTAIN:
> > +        while (avpriv_atomic_ptr_cas(state, NULL, mutex))
> > +            ;
> > +
> > +        return 0;
> > +    case AV_LOCK_RELEASE:
> > +         if (avpriv_atomic_ptr_cas(state, mutex, NULL) != mutex)
> > +             av_assert0(0);
> > +
> > +        return 0;
> > +    case AV_LOCK_DESTROY:
> > +        return 0;
> > +    }
> > +    return 1;
> > +}
> > +
> >  volatile int ff_avcodec_locked;
> >  static int volatile entangled_thread_counter = 0;
> > -static int (*lockmgr_cb)(void **mutex, enum AVLockOp op);
> > +static int (*lockmgr_cb)(void **mutex, enum AVLockOp op) =
> > default_lockmgr_cb;
> >  static void *codec_mutex;
> >  static void *avformat_mutex;
> >
> > --
> > 1.7.9.5
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel at ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> 
> Why this was not done before?

the avpriv_atomic_ stuff didnt exist before

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct answer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131017/bf89bbbc/attachment.asc>


More information about the ffmpeg-devel mailing list