qsv: Use std::once_flag

GLib's once implementation will take mutex every time
in case of non-GCC build

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4005>
This commit is contained in:
Seungha Yang 2023-02-19 22:43:57 +09:00 committed by GStreamer Marge Bot
parent 5eb4253547
commit e48869e269
7 changed files with 37 additions and 37 deletions

View file

@ -83,11 +83,10 @@ gst_qsv_av1_enc_rate_control_get_type (void)
{0, nullptr, nullptr}
};
if (g_once_init_enter (&rate_control_type)) {
GType type =
GST_QSV_CALL_ONCE_BEGIN {
rate_control_type =
g_enum_register_static ("GstQsvAV1EncRateControl", rate_controls);
g_once_init_leave (&rate_control_type, type);
}
} GST_QSV_CALL_ONCE_END;
return rate_control_type;
}

View file

@ -74,11 +74,10 @@ gst_qsv_coding_option_get_type (void)
{0, nullptr, nullptr}
};
if (g_once_init_enter (&coding_opt_type)) {
GType type = g_enum_register_static ("GstQsvCodingOption",
GST_QSV_CALL_ONCE_BEGIN {
coding_opt_type = g_enum_register_static ("GstQsvCodingOption",
coding_opts);
g_once_init_leave (&coding_opt_type, type);
}
} GST_QSV_CALL_ONCE_END;
return coding_opt_type;
}

View file

@ -95,11 +95,10 @@ gst_qsv_h264_enc_sei_insert_mode_get_type (void)
{0, nullptr, nullptr}
};
if (g_once_init_enter (&sei_insert_mode_type)) {
GType type =
GST_QSV_CALL_ONCE_BEGIN {
sei_insert_mode_type =
g_enum_register_static ("GstQsvH264EncSeiInsertMode", insert_modes);
g_once_init_leave (&sei_insert_mode_type, type);
}
} GST_QSV_CALL_ONCE_END;
return sei_insert_mode_type;
}
@ -188,11 +187,10 @@ gst_qsv_h264_enc_rate_control_get_type (void)
{0, nullptr, nullptr}
};
if (g_once_init_enter (&rate_control_type)) {
GType type =
GST_QSV_CALL_ONCE_BEGIN {
rate_control_type =
g_enum_register_static ("GstQsvH264EncRateControl", rate_controls);
g_once_init_leave (&rate_control_type, type);
}
} GST_QSV_CALL_ONCE_END;
return rate_control_type;
}
@ -240,11 +238,10 @@ gst_qsv_h264_enc_rc_lookahead_ds_get_type (void)
{0, nullptr, nullptr}
};
if (g_once_init_enter (&rc_lookahead_ds_type)) {
GType type =
GST_QSV_CALL_ONCE_BEGIN {
rc_lookahead_ds_type =
g_enum_register_static ("GstQsvH264EncRCLookAheadDS", rc_lookahead_ds);
g_once_init_leave (&rc_lookahead_ds_type, type);
}
} GST_QSV_CALL_ONCE_END;
return rc_lookahead_ds_type;
}

View file

@ -94,11 +94,10 @@ gst_qsv_h265_enc_sei_insert_mode_get_type (void)
{0, nullptr, nullptr}
};
if (g_once_init_enter (&sei_insert_mode_type)) {
GType type =
GST_QSV_CALL_ONCE_BEGIN {
sei_insert_mode_type =
g_enum_register_static ("GstQsvH265EncSeiInsertMode", insert_modes);
g_once_init_leave (&sei_insert_mode_type, type);
}
} GST_QSV_CALL_ONCE_END;
return sei_insert_mode_type;
}
@ -158,11 +157,10 @@ gst_qsv_h265_enc_rate_control_get_type (void)
{0, nullptr, nullptr}
};
if (g_once_init_enter (&rate_control_type)) {
GType type =
GST_QSV_CALL_ONCE_BEGIN {
rate_control_type =
g_enum_register_static ("GstQsvH265EncRateControl", rate_controls);
g_once_init_leave (&rate_control_type, type);
}
} GST_QSV_CALL_ONCE_END;
return rate_control_type;
}

View file

@ -39,12 +39,9 @@ static mfxLoader _loader = nullptr;
mfxLoader
gst_qsv_get_loader (void)
{
static gsize load_once = 0;
if (g_once_init_enter (&load_once)) {
GST_QSV_CALL_ONCE_BEGIN {
_loader = MFXLoad ();
g_once_init_leave (&load_once, 1);
}
} GST_QSV_CALL_ONCE_END;
return _loader;
}

View file

@ -76,3 +76,14 @@ static const GstQsvResolution gst_qsv_resolutions[] = {
};
G_END_DECLS
#ifdef __cplusplus
#include <mutex>
#define GST_QSV_CALL_ONCE_BEGIN \
static std::once_flag __once_flag; \
std::call_once (__once_flag, [&]()
#define GST_QSV_CALL_ONCE_END )
#endif /* __cplusplus */

View file

@ -91,11 +91,10 @@ gst_qsv_vp9_enc_rate_control_get_type (void)
{0, nullptr, nullptr}
};
if (g_once_init_enter (&rate_control_type)) {
GType type =
GST_QSV_CALL_ONCE_BEGIN {
rate_control_type =
g_enum_register_static ("GstQsvVP9EncRateControl", rate_controls);
g_once_init_leave (&rate_control_type, type);
}
} GST_QSV_CALL_ONCE_END;
return rate_control_type;
}