mirror of https://git.ffmpeg.org/ffmpeg.git
avformat/format: Fix registering a format more than once and related races
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
a887fbb582
commit
4cc896ea5f
|
@ -62,20 +62,24 @@ void av_register_input_format(AVInputFormat *format)
|
||||||
{
|
{
|
||||||
AVInputFormat **p = last_iformat;
|
AVInputFormat **p = last_iformat;
|
||||||
|
|
||||||
format->next = NULL;
|
// Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
|
||||||
while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
|
while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
|
||||||
p = &(*p)->next;
|
p = &(*p)->next;
|
||||||
last_iformat = &format->next;
|
|
||||||
|
if (!format->next)
|
||||||
|
last_iformat = &format->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
void av_register_output_format(AVOutputFormat *format)
|
void av_register_output_format(AVOutputFormat *format)
|
||||||
{
|
{
|
||||||
AVOutputFormat **p = last_oformat;
|
AVOutputFormat **p = last_oformat;
|
||||||
|
|
||||||
format->next = NULL;
|
// Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
|
||||||
while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
|
while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
|
||||||
p = &(*p)->next;
|
p = &(*p)->next;
|
||||||
last_oformat = &format->next;
|
|
||||||
|
if (!format->next)
|
||||||
|
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