aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-12-06 15:24:10 +0100
committerMichael Niedermayer <michaelni@gmx.at>2013-12-24 01:05:47 +0100
commit66a9edfcf677f2673b5163f8008bdc7d0454074c (patch)
tree845edd94ea6a7acf0ca36ec378b01e06c330efb6
parenta9382fc15c15c0517e41db8a294afc4c7696ba19 (diff)
downloadffmpeg-66a9edfcf677f2673b5163f8008bdc7d0454074c.tar.gz
do O(1) instead of O(n) atomic operations in register functions
about 1ms faster startup time Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 133fbfc7811ffae7b97dd129fcd0b5e646742362) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/utils.c5
-rw-r--r--libavfilter/avfilter.c2
-rw-r--r--libavformat/format.c4
3 files changed, 6 insertions, 5 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 6609f20ef7..9acf7bd770 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -163,7 +163,8 @@ av_cold void avcodec_register(AVCodec *codec)
avcodec_init();
p = &first_avcodec;
codec->next = NULL;
- while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
+
+ while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
p = &(*p)->next;
if (codec->init_static_data)
@@ -3013,7 +3014,7 @@ void av_register_hwaccel(AVHWAccel *hwaccel)
{
AVHWAccel **p = &first_hwaccel;
hwaccel->next = NULL;
- while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, hwaccel))
+ while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, hwaccel))
p = &(*p)->next;
}
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 251f6ae38d..e92f3e543b 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -468,7 +468,7 @@ int avfilter_register(AVFilter *filter)
filter->next = NULL;
- while(avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
+ while(*f || avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
f = &(*f)->next;
return 0;
diff --git a/libavformat/format.c b/libavformat/format.c
index ac9100b604..36c0131c12 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -54,7 +54,7 @@ void av_register_input_format(AVInputFormat *format)
AVInputFormat **p = &first_iformat;
format->next = NULL;
- while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
+ while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
p = &(*p)->next;
}
@@ -63,7 +63,7 @@ void av_register_output_format(AVOutputFormat *format)
AVOutputFormat **p = &first_oformat;
format->next = NULL;
- while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
+ while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
p = &(*p)->next;
}