do O(1) instead of O(n) atomic operations in register functions
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 6 Dec 2013 14:24:10 +0000 (15:24 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 7 Jan 2014 02:05:30 +0000 (03:05 +0100)
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>
libavcodec/utils.c
libavfilter/avfilter.c
libavformat/format.c

index ae32a35..554b30e 100644 (file)
@@ -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;
 }
 
index f31968f..c9c8acc 100644 (file)
@@ -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;
index ac9100b..36c0131 100644 (file)
@@ -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;
 }