mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-20 06:20:40 +00:00
avformat: use mutexes instead of atomics in av_register_{input,output}_format()
Reviewed-by: wm4 <nfxjfg@googlemail.com> Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
9ed4ebc530
commit
57960b1f28
@ -19,10 +19,10 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "libavutil/atomic.h"
|
|
||||||
#include "libavutil/avstring.h"
|
#include "libavutil/avstring.h"
|
||||||
#include "libavutil/bprint.h"
|
#include "libavutil/bprint.h"
|
||||||
#include "libavutil/opt.h"
|
#include "libavutil/opt.h"
|
||||||
|
#include "libavutil/thread.h"
|
||||||
|
|
||||||
#include "avio_internal.h"
|
#include "avio_internal.h"
|
||||||
#include "avformat.h"
|
#include "avformat.h"
|
||||||
@ -58,28 +58,40 @@ AVOutputFormat *av_oformat_next(const AVOutputFormat *f)
|
|||||||
return first_oformat;
|
return first_oformat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static AVMutex iformat_register_mutex = AV_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
void av_register_input_format(AVInputFormat *format)
|
void av_register_input_format(AVInputFormat *format)
|
||||||
{
|
{
|
||||||
AVInputFormat **p = last_iformat;
|
AVInputFormat **p;
|
||||||
|
|
||||||
// Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
|
ff_mutex_lock(&iformat_register_mutex);
|
||||||
while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
|
p = last_iformat;
|
||||||
|
|
||||||
|
while (*p)
|
||||||
p = &(*p)->next;
|
p = &(*p)->next;
|
||||||
|
*p = format;
|
||||||
|
format->next = NULL;
|
||||||
|
last_iformat = &format->next;
|
||||||
|
|
||||||
if (!format->next)
|
ff_mutex_unlock(&iformat_register_mutex);
|
||||||
last_iformat = &format->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static AVMutex oformat_register_mutex = AV_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
void av_register_output_format(AVOutputFormat *format)
|
void av_register_output_format(AVOutputFormat *format)
|
||||||
{
|
{
|
||||||
AVOutputFormat **p = last_oformat;
|
AVOutputFormat **p;
|
||||||
|
|
||||||
// Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
|
ff_mutex_lock(&oformat_register_mutex);
|
||||||
while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
|
p = last_oformat;
|
||||||
|
|
||||||
|
while (*p)
|
||||||
p = &(*p)->next;
|
p = &(*p)->next;
|
||||||
|
*p = format;
|
||||||
|
format->next = NULL;
|
||||||
|
last_oformat = &format->next;
|
||||||
|
|
||||||
if (!format->next)
|
ff_mutex_unlock(&oformat_register_mutex);
|
||||||
last_oformat = &format->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int av_match_ext(const char *filename, const char *extensions)
|
int av_match_ext(const char *filename, const char *extensions)
|
||||||
|
Loading…
Reference in New Issue
Block a user