[FFmpeg-devel] [PATCH] avcodec/utils: use a default lock manager that uses a spinlock
Don Moir
donmoir at comcast.net
Fri Oct 18 20:39:23 CEST 2013
----- Original Message -----
From: "Paul B Mahol" <onemda at gmail.com>
To: "FFmpeg development discussions and patches" <ffmpeg-devel at ffmpeg.org>
Sent: Thursday, October 17, 2013 9:48 AM
Subject: Re: [FFmpeg-devel] [PATCH] avcodec/utils: use a default lock manager that uses a spinlock
> 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;
+ case AV_LOCK_OBTAIN:
+ while (avpriv_atomic_ptr_cas(state, NULL, mutex))
+ ;
+
+ return 0;
Seems the while loop here will cause CPU to spike high. Suggest whatever you use for Sleep be incorporated in loop.
More information about the ffmpeg-devel
mailing list