diff mbox

[FFmpeg-devel,4/4] avfilter: use a mutex instead of atomics in avfilter_register()

Message ID 20180104181904.5816-4-jamrial@gmail.com
State Superseded
Headers show

Commit Message

James Almer Jan. 4, 2018, 6:19 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
With this, the last users of libavutil's atomic wrappers are dealt
with.

 libavfilter/avfilter.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

wm4 Jan. 4, 2018, 6:28 p.m. UTC | #1
On Thu,  4 Jan 2018 15:19:04 -0300
James Almer <jamrial@gmail.com> wrote:

> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> With this, the last users of libavutil's atomic wrappers are dealt
> with.

Technically, you need to lock when reading the next pointers too? Don't
know if that actually matters.
James Almer Jan. 4, 2018, 6:45 p.m. UTC | #2
On 1/4/2018 3:28 PM, wm4 wrote:
> On Thu,  4 Jan 2018 15:19:04 -0300
> James Almer <jamrial@gmail.com> wrote:
> 
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> With this, the last users of libavutil's atomic wrappers are dealt
>> with.
> 
> Technically, you need to lock when reading the next pointers too? Don't
> know if that actually matters.

Probably not seeing it's currently not using atomics to read them.
Zhanbang He Jan. 5, 2018, 2:32 a.m. UTC | #3
i think we do not need lock. and we need keep on the last codec pointer.



On Fri, Jan 5, 2018 at 2:28 AM, wm4 <nfxjfg@googlemail.com> wrote:

> On Thu,  4 Jan 2018 15:19:04 -0300
> James Almer <jamrial@gmail.com> wrote:
>
> > Signed-off-by: James Almer <jamrial@gmail.com>
> > ---
> > With this, the last users of libavutil's atomic wrappers are dealt
> > with.
>
> Technically, you need to lock when reading the next pointers too? Don't
> know if that actually matters.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
diff mbox

Patch

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index b98b32bacb..945fc65e5f 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -19,7 +19,6 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavutil/atomic.h"
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/buffer.h"
@@ -33,6 +32,7 @@ 
 #include "libavutil/pixdesc.h"
 #include "libavutil/rational.h"
 #include "libavutil/samplefmt.h"
+#include "libavutil/thread.h"
 
 #define FF_INTERNAL_FIELDS 1
 #include "framequeue.h"
@@ -574,7 +574,6 @@  int avfilter_process_command(AVFilterContext *filter, const char *cmd, const cha
 }
 
 static AVFilter *first_filter;
-static AVFilter **last_filter = &first_filter;
 
 const AVFilter *avfilter_get_by_name(const char *name)
 {
@@ -590,18 +589,24 @@  const AVFilter *avfilter_get_by_name(const char *name)
     return NULL;
 }
 
+static AVMutex filter_register_mutex = AV_MUTEX_INITIALIZER;
+
 int avfilter_register(AVFilter *filter)
 {
-    AVFilter **f = last_filter;
+    AVFilter **f;
 
     /* the filter must select generic or internal exclusively */
     av_assert0((filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE) != AVFILTER_FLAG_SUPPORT_TIMELINE);
 
-    filter->next = NULL;
+    ff_mutex_lock(&filter_register_mutex);
+    f = &first_filter;
 
-    while(*f || avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
+    while (*f)
         f = &(*f)->next;
-    last_filter = &filter->next;
+    *f = filter;
+    filter->next = NULL;
+
+    ff_mutex_unlock(&filter_register_mutex);
 
     return 0;
 }