Guest User

Untitled

a guest
Jan 4th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.31 KB | None | 0 0
  1. diff --git a/libavcodec/parser.c b/libavcodec/parser.c
  2. index 670680ea7c..747ea2ee8a 100644
  3. --- a/libavcodec/parser.c
  4. +++ b/libavcodec/parser.c
  5. @@ -25,9 +25,9 @@
  6.  #include <string.h>
  7.  
  8.  #include "libavutil/avassert.h"
  9. -#include "libavutil/atomic.h"
  10.  #include "libavutil/internal.h"
  11.  #include "libavutil/mem.h"
  12. +#include "libavutil/thread.h"
  13.  
  14.  #include "internal.h"
  15.  #include "parser.h"
  16. @@ -42,11 +42,14 @@ AVCodecParser *av_parser_next(const AVCodecParser *p)
  17.          return av_first_parser;
  18.  }
  19.  
  20. +static AVMutex parser_register_mutex = AV_MUTEX_INITIALIZER;
  21. +
  22.  void av_register_codec_parser(AVCodecParser *parser)
  23.  {
  24. -    do {
  25. -        parser->next = av_first_parser;
  26. -    } while (parser->next != avpriv_atomic_ptr_cas((void * volatile *)&av_first_parser, parser->next, parser));
  27. +    ff_mutex_lock(&parser_register_mutex);
  28. +    parser->next = av_first_parser;
  29. +    av_first_parser = parser;
  30. +    ff_mutex_unlock(&parser_register_mutex);
  31.  }
  32.  
  33.  AVCodecParserContext *av_parser_init(int codec_id)
  34. diff --git a/libavcodec/utils.c b/libavcodec/utils.c
  35. index dfbfe98d63..58216b984a 100644
  36. --- a/libavcodec/utils.c
  37. +++ b/libavcodec/utils.c
  38. @@ -26,7 +26,6 @@
  39.   */
  40.  
  41.  #include "config.h"
  42. -#include "libavutil/atomic.h"
  43.  #include "libavutil/attributes.h"
  44.  #include "libavutil/avassert.h"
  45.  #include "libavutil/avstring.h"
  46. @@ -95,7 +94,6 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
  47.  
  48.  /* encoder management */
  49.  static AVCodec *first_avcodec = NULL;
  50. -static AVCodec **last_avcodec = &first_avcodec;
  51.  
  52.  AVCodec *av_codec_next(const AVCodec *c)
  53.  {
  54. @@ -127,16 +125,19 @@ int av_codec_is_decoder(const AVCodec *codec)
  55.      return codec && (codec->decode || codec->receive_frame);
  56.  }
  57.  
  58. +static AVMutex codec_register_mutex = AV_MUTEX_INITIALIZER;
  59. +
  60.  av_cold void avcodec_register(AVCodec *codec)
  61.  {
  62.      AVCodec **p;
  63.      avcodec_init();
  64. -    p = last_avcodec;
  65. -    codec->next = NULL;
  66. -
  67. -    while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, codec))
  68. +    ff_mutex_lock(&codec_register_mutex);
  69. +    p = &first_avcodec;
  70. +    while (*p)
  71.          p = &(*p)->next;
  72. -    last_avcodec = &codec->next;
  73. +    *p          = codec;
  74. +    codec->next = NULL;
  75. +    ff_mutex_unlock(&codec_register_mutex);
  76.  
  77.      if (codec->init_static_data)
  78.          codec->init_static_data(codec);
  79. diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
  80. index b98b32bacb..0c1a5b6488 100644
  81. --- a/libavfilter/avfilter.c
  82. +++ b/libavfilter/avfilter.c
  83. @@ -19,7 +19,6 @@
  84.   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  85.   */
  86.  
  87. -#include "libavutil/atomic.h"
  88.  #include "libavutil/avassert.h"
  89.  #include "libavutil/avstring.h"
  90.  #include "libavutil/buffer.h"
  91. @@ -33,6 +32,7 @@
  92.  #include "libavutil/pixdesc.h"
  93.  #include "libavutil/rational.h"
  94.  #include "libavutil/samplefmt.h"
  95. +#include "libavutil/thread.h"
  96.  
  97.  #define FF_INTERNAL_FIELDS 1
  98.  #include "framequeue.h"
  99. @@ -574,7 +574,6 @@ int avfilter_process_command(AVFilterContext *filter, const char *cmd, const cha
  100.  }
  101.  
  102.  static AVFilter *first_filter;
  103. -static AVFilter **last_filter = &first_filter;
  104.  
  105.  const AVFilter *avfilter_get_by_name(const char *name)
  106.  {
  107. @@ -590,18 +589,23 @@ const AVFilter *avfilter_get_by_name(const char *name)
  108.      return NULL;
  109.  }
  110.  
  111. +static AVMutex filter_register_mutex = AV_MUTEX_INITIALIZER;
  112. +
  113.  int avfilter_register(AVFilter *filter)
  114.  {
  115. -    AVFilter **f = last_filter;
  116. +    AVFilter **f;
  117.  
  118.      /* the filter must select generic or internal exclusively */
  119.      av_assert0((filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE) != AVFILTER_FLAG_SUPPORT_TIMELINE);
  120.  
  121. -    filter->next = NULL;
  122. +    ff_mutex_lock(&filter_register_mutex);
  123. +    f = &first_filter;
  124.  
  125. -    while(*f || avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
  126. +    while (*f)
  127.          f = &(*f)->next;
  128. -    last_filter = &filter->next;
  129. +    *f = filter;
  130. +    filter->next = NULL;
  131. +    ff_mutex_unlock(&filter_register_mutex);
  132.  
  133.      return 0;
  134.  }
  135. diff --git a/libavformat/format.c b/libavformat/format.c
  136. index 38ca2a3465..ad37923e25 100644
  137. --- a/libavformat/format.c
  138. +++ b/libavformat/format.c
  139. @@ -19,10 +19,10 @@
  140.   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  141.   */
  142.  
  143. -#include "libavutil/atomic.h"
  144.  #include "libavutil/avstring.h"
  145.  #include "libavutil/bprint.h"
  146.  #include "libavutil/opt.h"
  147. +#include "libavutil/thread.h"
  148.  
  149.  #include "avio_internal.h"
  150.  #include "avformat.h"
  151. @@ -39,9 +39,6 @@ static AVInputFormat *first_iformat = NULL;
  152.  /** head of registered output format linked list */
  153.  static AVOutputFormat *first_oformat = NULL;
  154.  
  155. -static AVInputFormat **last_iformat = &first_iformat;
  156. -static AVOutputFormat **last_oformat = &first_oformat;
  157. -
  158.  AVInputFormat *av_iformat_next(const AVInputFormat *f)
  159.  {
  160.      if (f)
  161. @@ -58,28 +55,35 @@ AVOutputFormat *av_oformat_next(const AVOutputFormat *f)
  162.          return first_oformat;
  163.  }
  164.  
  165. +static AVMutex iformat_register_mutex = AV_MUTEX_INITIALIZER;
  166. +
  167.  void av_register_input_format(AVInputFormat *format)
  168.  {
  169. -    AVInputFormat **p = last_iformat;
  170. +    AVInputFormat **p;
  171. +    ff_mutex_lock(&iformat_register_mutex);
  172. +    p = &first_iformat;
  173.  
  174. -    // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
  175. -    while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
  176. +    while (*p)
  177.          p = &(*p)->next;
  178.  
  179. -    if (!format->next)
  180. -        last_iformat = &format->next;
  181. +    *p = format;
  182. +    format->next = NULL;
  183. +    ff_mutex_unlock(&iformat_register_mutex);
  184.  }
  185.  
  186. +static AVMutex oformat_register_mutex = AV_MUTEX_INITIALIZER;
  187. +
  188.  void av_register_output_format(AVOutputFormat *format)
  189.  {
  190. -    AVOutputFormat **p = last_oformat;
  191. +    AVOutputFormat **p = &first_oformat;
  192.  
  193. -    // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
  194. -    while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
  195. +    ff_mutex_lock(&oformat_register_mutex);
  196. +    while (*p)
  197.          p = &(*p)->next;
  198.  
  199. -    if (!format->next)
  200. -        last_oformat = &format->next;
  201. +    *p = format;
  202. +    format->next = NULL;
  203. +    ff_mutex_unlock(&oformat_register_mutex);
  204.  }
  205.  
  206.  int av_match_ext(const char *filename, const char *extensions)
Advertisement
Add Comment
Please, Sign In to add comment