History

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

about 1ms faster startup time

Michael Niedermayer committed 12 years ago

Commit 133fbfc1 parent 2b215f33 files · +6 −5Browse files

Unified · Split

3 files
  1. libavcodec/utils.c +3 −2
  2. libavfilter/avfilter.c +1 −1
  3. libavformat/format.c +2 −2
libavcodec/utils.c+3−2
@@ -206,7 +206,8 @@ av_cold void avcodec_register(AVCodec *codec) · 205 unmodified lines
206206 avcodec_init();
207207 p = &first_avcodec;
208208 codec->next = NULL;
209− while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
209+
210+ while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
210211 p = &(*p)->next;
211212
212213 if (codec->init_static_data)
@@ -3191,7 +3192,7 @@ void av_register_hwaccel(AVHWAccel *hwaccel) · 2978 unmodified lines
31913192 {
31923193 AVHWAccel **p = &first_hwaccel;
31933194 hwaccel->next = NULL;
3194− while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, hwaccel))
3195+ while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, hwaccel))
31953196 p = &(*p)->next;
31963197 }
31973198
libavfilter/avfilter.c+1−1
@@ -490,7 +490,7 @@ int avfilter_register(AVFilter *filter) · 489 unmodified lines
490490
491491 filter->next = NULL;
492492
493− while(avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
493+ while(*f || avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
494494 f = &(*f)->next;
495495
496496 return 0;
libavformat/format.c+2−2
@@ -54,7 +54,7 @@ void av_register_input_format(AVInputFormat *format) · 53 unmodified lines
5454 AVInputFormat **p = &first_iformat;
5555
5656 format->next = NULL;
57− while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
57+ while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
5858 p = &(*p)->next;
5959 }
6060
@@ -63,7 +63,7 @@ void av_register_output_format(AVOutputFormat *format) · 2 unmodified lines
6363 AVOutputFormat **p = &first_oformat;
6464
6565 format->next = NULL;
66− while(avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
66+ while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
6767 p = &(*p)->next;
6868 }
6969

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t