[FFmpeg-cvslog] do O(1) instead of O(n) atomic operations in register functions

Michael Niedermayer git at videolan.org
Tue Jan 7 03:47:22 CET 2014


ffmpeg | branch: release/2.1 | Michael Niedermayer <michaelni at gmx.at> | Fri Dec  6 15:24:10 2013 +0100| [cf6cf50ac689e3dc69c54b66495cd4951105bf61] | committer: Michael Niedermayer

do O(1) instead of O(n) atomic operations in register functions

about 1ms faster startup time

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
(cherry picked from commit 133fbfc7811ffae7b97dd129fcd0b5e646742362)

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cf6cf50ac689e3dc69c54b66495cd4951105bf61
---

 libavcodec/utils.c     |    5 +++--
 libavfilter/avfilter.c |    2 +-
 libavformat/format.c   |    4 ++--
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index ae32a35..554b30e 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -218,7 +218,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)
@@ -3182,7 +3183,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 f31968f..c9c8acc 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -487,7 +487,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 ac9100b..36c0131 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;
 }
 



More information about the ffmpeg-cvslog mailing list