From: Matthew Waters Date: Fri, 19 Mar 2021 06:42:36 +0000 (+1100) Subject: gst: don't use volatile to mean atomic X-Git-Tag: 1.19.3~503^2~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d270654c48c19afc3234e126269bf613540b44d8;p=platform%2Fupstream%2Fgstreamer.git gst: don't use volatile to mean atomic volatile is not sufficient to provide atomic guarantees and real atomics should be used instead. GCC 11 has started warning about using volatile with atomic operations. https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1719 Discovered in https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/issues/868 Part-of: --- diff --git a/gst-libs/gst/vaapi/gstvaapicontext.c b/gst-libs/gst/vaapi/gstvaapicontext.c index 52fd751..88cd110 100644 --- a/gst-libs/gst/vaapi/gstvaapicontext.c +++ b/gst-libs/gst/vaapi/gstvaapicontext.c @@ -51,7 +51,7 @@ static void _init_vaapi_context_debug (void) { #ifndef GST_DISABLE_GST_DEBUG - static volatile gsize _init = 0; + static gsize _init = 0; if (g_once_init_enter (&_init)) { GST_DEBUG_CATEGORY_INIT (gst_debug_vaapi_context, "vaapicontext", 0, diff --git a/gst-libs/gst/vaapi/gstvaapicontext.h b/gst-libs/gst/vaapi/gstvaapicontext.h index 820fa63..7117722 100644 --- a/gst-libs/gst/vaapi/gstvaapicontext.h +++ b/gst-libs/gst/vaapi/gstvaapicontext.h @@ -100,7 +100,7 @@ struct _GstVaapiContextInfo struct _GstVaapiContext { /*< private >*/ - volatile gint ref_count; + gint ref_count; GstVaapiDisplay *display; GstVaapiID object_id; diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c index 83d26f0..6c103ac 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder.c @@ -1822,7 +1822,7 @@ out: GType gst_vaapi_encoder_tune_get_type (void) { - static volatile gsize g_type = 0; + static gsize g_type = 0; static const GEnumValue encoder_tune_values[] = { /* *INDENT-OFF* */ @@ -1850,7 +1850,7 @@ gst_vaapi_encoder_tune_get_type (void) GType gst_vaapi_encoder_mbbrc_get_type (void) { - static volatile gsize g_type = 0; + static gsize g_type = 0; if (g_once_init_enter (&g_type)) { static const GEnumValue encoder_mbbrc_values[] = { diff --git a/gst-libs/gst/vaapi/gstvaapifilter.c b/gst-libs/gst/vaapi/gstvaapifilter.c index a9443e4..e0b3cd5 100644 --- a/gst-libs/gst/vaapi/gstvaapifilter.c +++ b/gst-libs/gst/vaapi/gstvaapifilter.c @@ -38,7 +38,7 @@ struct _GstVaapiFilterOpData { GstVaapiFilterOp op; GParamSpec *pspec; - volatile gint ref_count; + gint ref_count; guint va_type; guint va_subtype; gpointer va_caps; @@ -550,7 +550,7 @@ op_data_new (GstVaapiFilterOp op, GParamSpec * pspec) op_data->op = op; op_data->pspec = pspec; - op_data->ref_count = 1; + g_atomic_int_set (&op_data->ref_count, 1); op_data->va_buffer = VA_INVALID_ID; switch (op) { diff --git a/gst-libs/gst/vaapi/gstvaapiminiobject.c b/gst-libs/gst/vaapi/gstvaapiminiobject.c index 7b18983..30586b0 100644 --- a/gst-libs/gst/vaapi/gstvaapiminiobject.c +++ b/gst-libs/gst/vaapi/gstvaapiminiobject.c @@ -70,7 +70,7 @@ gst_vaapi_mini_object_new (const GstVaapiMiniObjectClass * object_class) return NULL; object->object_class = object_class; - object->ref_count = 1; + g_atomic_int_set (&object->ref_count, 1); object->flags = 0; return object; } diff --git a/gst-libs/gst/vaapi/gstvaapiminiobject.h b/gst-libs/gst/vaapi/gstvaapiminiobject.h index 778fc07..52f2863 100644 --- a/gst-libs/gst/vaapi/gstvaapiminiobject.h +++ b/gst-libs/gst/vaapi/gstvaapiminiobject.h @@ -120,7 +120,7 @@ struct _GstVaapiMiniObject { /*< private >*/ gconstpointer object_class; - volatile gint ref_count; + gint ref_count; guint flags; }; diff --git a/gst-libs/gst/vaapi/gstvaapitexture_glx.c b/gst-libs/gst/vaapi/gstvaapitexture_glx.c index 273afc9..76f450a 100644 --- a/gst-libs/gst/vaapi/gstvaapitexture_glx.c +++ b/gst-libs/gst/vaapi/gstvaapitexture_glx.c @@ -249,7 +249,7 @@ GstVaapiGLApi gl_get_curent_api_once () { static GstVaapiGLApi cur_api = GST_VAAPI_GL_API_NONE; - static volatile gsize _init = 0; + static gsize _init = 0; if (g_once_init_enter (&_init)) { cur_api = gl_get_current_api (NULL, NULL); diff --git a/gst-libs/gst/vaapi/gstvaapiutils_egl.c b/gst-libs/gst/vaapi/gstvaapiutils_egl.c index 0c2a1f5..99ae37d 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_egl.c +++ b/gst-libs/gst/vaapi/gstvaapiutils_egl.c @@ -614,7 +614,7 @@ egl_display_thread (gpointer data) g_cond_broadcast (&display->gl_thread_ready); g_mutex_unlock (&display->mutex); - while (!display->gl_thread_cancel) { + while (!g_atomic_int_get (&display->gl_thread_cancel)) { EglMessage *const msg = g_async_queue_timeout_pop (display->gl_queue, 100000); @@ -671,7 +671,7 @@ egl_display_init (EglDisplay * display) static void egl_display_finalize (EglDisplay * display) { - display->gl_thread_cancel = TRUE; + g_atomic_int_set (&display->gl_thread_cancel, TRUE); g_thread_join (display->gl_thread); g_cond_clear (&display->gl_thread_ready); g_mutex_clear (&display->mutex); diff --git a/gst-libs/gst/vaapi/gstvaapiutils_egl.h b/gst-libs/gst/vaapi/gstvaapiutils_egl.h index abf3735..20b553e 100644 --- a/gst-libs/gst/vaapi/gstvaapiutils_egl.h +++ b/gst-libs/gst/vaapi/gstvaapiutils_egl.h @@ -120,7 +120,7 @@ struct egl_display_s GMutex mutex; GThread *gl_thread; GCond gl_thread_ready; - volatile gboolean gl_thread_cancel; + gboolean gl_thread_cancel; GAsyncQueue *gl_queue; gboolean created; }; diff --git a/gst-libs/gst/vaapi/gstvaapivalue.c b/gst-libs/gst/vaapi/gstvaapivalue.c index 1e01213..62e440b 100644 --- a/gst-libs/gst/vaapi/gstvaapivalue.c +++ b/gst-libs/gst/vaapi/gstvaapivalue.c @@ -50,7 +50,7 @@ default_free_func (gpointer data) GType gst_vaapi_point_get_type (void) { - static volatile gsize g_type = 0; + static gsize g_type = 0; if (g_once_init_enter (&g_type)) { GType type = @@ -67,7 +67,7 @@ gst_vaapi_point_get_type (void) GType gst_vaapi_rectangle_get_type (void) { - static volatile gsize g_type = 0; + static gsize g_type = 0; if (g_once_init_enter (&g_type)) { GType type = @@ -85,7 +85,7 @@ gst_vaapi_rectangle_get_type (void) GType gst_vaapi_render_mode_get_type (void) { - static volatile gsize g_type = 0; + static gsize g_type = 0; static const GEnumValue render_modes[] = { {GST_VAAPI_RENDER_MODE_OVERLAY, @@ -108,7 +108,7 @@ gst_vaapi_render_mode_get_type (void) GType gst_vaapi_rotation_get_type (void) { - static volatile gsize g_type = 0; + static gsize g_type = 0; static const GEnumValue rotation_values[] = { {GST_VAAPI_ROTATION_0, @@ -137,7 +137,7 @@ gst_vaapi_rotation_get_type (void) GType gst_vaapi_rate_control_get_type (void) { - static volatile gsize g_type = 0; + static gsize g_type = 0; static const GEnumValue rate_control_values[] = { {GST_VAAPI_RATECONTROL_NONE, diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c b/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c index caf1dc6..394a089 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow_wayland.c @@ -98,7 +98,7 @@ struct _GstVaapiWindowWaylandPrivate guint is_shown:1; guint fullscreen_on_show:1; guint sync_failed:1; - volatile guint num_frames_pending; + guint num_frames_pending; gint configure_pending; gboolean need_vpp; gboolean dmabuf_broken; diff --git a/gst/vaapi/gstvaapipluginbase.c b/gst/vaapi/gstvaapipluginbase.c index 3a8664b..a670e97 100644 --- a/gst/vaapi/gstvaapipluginbase.c +++ b/gst/vaapi/gstvaapipluginbase.c @@ -1546,7 +1546,7 @@ static void _init_performance_debug (void) { #ifndef GST_DISABLE_GST_DEBUG - static volatile gsize _init = 0; + static gsize _init = 0; if (g_once_init_enter (&_init)) { GST_DEBUG_CATEGORY_GET (CAT_PERFORMANCE, "GST_PERFORMANCE"); diff --git a/gst/vaapi/gstvaapisink.c b/gst/vaapi/gstvaapisink.c index e722b71..9b5ae98 100644 --- a/gst/vaapi/gstvaapisink.c +++ b/gst/vaapi/gstvaapisink.c @@ -976,7 +976,7 @@ static gpointer gst_vaapisink_event_thread (GstVaapiSink * sink) { GST_OBJECT_LOCK (sink); - while (!sink->event_thread_cancel) { + while (!g_atomic_int_get (&sink->event_thread_cancel)) { GST_OBJECT_UNLOCK (sink); sink->backend->handle_events (sink); g_usleep (G_USEC_PER_SEC / 20); @@ -1001,7 +1001,7 @@ gst_vaapisink_set_event_handling (GstVaapiSink * sink, gboolean handle_events) if (sink->backend->pre_start_event_thread) sink->backend->pre_start_event_thread (sink); - sink->event_thread_cancel = FALSE; + g_atomic_int_set (&sink->event_thread_cancel, FALSE); sink->event_thread = g_thread_try_new ("vaapisink-events", (GThreadFunc) gst_vaapisink_event_thread, sink, NULL); } else if (!handle_events && sink->event_thread) { @@ -1012,7 +1012,7 @@ gst_vaapisink_set_event_handling (GstVaapiSink * sink, gboolean handle_events) /* Grab thread and mark it as NULL */ thread = sink->event_thread; sink->event_thread = NULL; - sink->event_thread_cancel = TRUE; + g_atomic_int_set (&sink->event_thread_cancel, TRUE); } GST_OBJECT_UNLOCK (sink); diff --git a/gst/vaapi/gstvaapisink.h b/gst/vaapi/gstvaapisink.h index 1fb6e83..525f422 100644 --- a/gst/vaapi/gstvaapisink.h +++ b/gst/vaapi/gstvaapisink.h @@ -99,7 +99,7 @@ struct _GstVaapiSink guint color_standard; gint32 view_id; GThread *event_thread; - volatile gboolean event_thread_cancel; + gboolean event_thread_cancel; /* Color balance values */ guint cb_changed; diff --git a/gst/vaapi/gstvaapivideocontext.c b/gst/vaapi/gstvaapivideocontext.c index bd3db01..ae3af85 100644 --- a/gst/vaapi/gstvaapivideocontext.c +++ b/gst/vaapi/gstvaapivideocontext.c @@ -44,7 +44,7 @@ static void _init_context_debug (void) { #ifndef GST_DISABLE_GST_DEBUG - static volatile gsize _init = 0; + static gsize _init = 0; if (g_once_init_enter (&_init)) { GST_DEBUG_CATEGORY_GET (GST_CAT_CONTEXT, "GST_CONTEXT"); diff --git a/gst/vaapi/gstvaapivideomemory.c b/gst/vaapi/gstvaapivideomemory.c index abf9715..750385a 100644 --- a/gst/vaapi/gstvaapivideomemory.c +++ b/gst/vaapi/gstvaapivideomemory.c @@ -47,7 +47,7 @@ static void _init_performance_debug (void) { #ifndef GST_DISABLE_GST_DEBUG - static volatile gsize _init = 0; + static gsize _init = 0; if (g_once_init_enter (&_init)) { GST_DEBUG_CATEGORY_GET (CAT_PERFORMANCE, "GST_PERFORMANCE"); @@ -60,7 +60,7 @@ static void _init_vaapi_video_memory_debug (void) { #ifndef GST_DISABLE_GST_DEBUG - static volatile gsize _init = 0; + static gsize _init = 0; if (g_once_init_enter (&_init)) { GST_DEBUG_CATEGORY_INIT (gst_debug_vaapivideomemory, "vaapivideomemory", 0, diff --git a/tests/internal/simple-decoder.c b/tests/internal/simple-decoder.c index 134b845..7575276 100644 --- a/tests/internal/simple-decoder.c +++ b/tests/internal/simple-decoder.c @@ -85,7 +85,7 @@ typedef struct GstVaapiDisplay *display; GstVaapiDecoder *decoder; GThread *decoder_thread; - volatile gboolean decoder_thread_cancel; + gboolean decoder_thread_cancel; GAsyncQueue *decoder_queue; GstVaapiCodec codec; guint fps_n; @@ -97,7 +97,7 @@ typedef struct guint window_width; guint window_height; GThread *render_thread; - volatile gboolean render_thread_cancel; + gboolean render_thread_cancel; GCond render_ready; RenderFrame *last_frame; GError *error; @@ -241,7 +241,7 @@ decoder_thread (gpointer data) pts = g_get_monotonic_time (); ofs = 0; - while (!app->decoder_thread_cancel) { + while (!g_atomic_int_get (&app->decoder_thread_cancel)) { if (G_UNLIKELY (ofs == app->file_size)) buffer = NULL; else { @@ -376,7 +376,7 @@ stop_decoder (App * app) { g_timer_stop (app->timer); - app->decoder_thread_cancel = TRUE; + g_atomic_int_set (&app->decoder_thread_cancel, TRUE); g_thread_join (app->decoder_thread); g_print ("Decoder thread stopped\n"); return TRUE; @@ -462,7 +462,7 @@ renderer_thread (gpointer data) g_print ("Render thread started\n"); - while (!app->render_thread_cancel) { + while (!g_atomic_int_get (&app->render_thread_cancel)) { rfp = g_async_queue_timeout_pop (app->decoder_queue, 1000000); if (rfp && !renderer_process (app, rfp)) break; @@ -497,7 +497,7 @@ start_renderer (App * app) static gboolean stop_renderer (App * app) { - app->render_thread_cancel = TRUE; + g_atomic_int_set (&app->render_thread_cancel, TRUE); g_thread_join (app->render_thread); g_print ("Render thread stopped\n");