[vlc-commits] [Git][videolan/vlc][master] 2 commits: threads: add data parameter to one-time callbacks
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Fri Nov 19 15:09:57 UTC 2021
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
47a00338 by Rémi Denis-Courmont at 2021-11-19T13:04:16+00:00
threads: add data parameter to one-time callbacks
- - - - -
a747e30b by Rémi Denis-Courmont at 2021-11-19T13:04:16+00:00
gst: use vlc_once() parameter
- - - - -
4 changed files:
- include/vlc_threads.h
- modules/codec/gstreamer/gstdecode.c
- modules/services_discovery/mtp.c
- src/misc/threads.c
Changes:
=====================================
include/vlc_threads.h
=====================================
@@ -590,8 +590,8 @@ typedef struct
* Executes a function one time.
*
* The first time this function is called with a given one-time initialization
- * object, it executes the provided callback.
- * Any further call with the same object will be a no-op.
+ * object, it executes the provided callback with the provided data pointer as
+ * sole parameter. Any further call with the same object will be a no-op..
*
* In the corner case that the first time execution is ongoing in another
* thread, then the function will wait for completion on the other thread
@@ -601,16 +601,19 @@ typedef struct
*
* \param once a one-time initialization object
* \param cb callback to execute (the first time)
+ * \param opaque data pointer for the callback
*/
-VLC_API void vlc_once(vlc_once_t *restrict once, void (*cb)(void));
+VLC_API void vlc_once(vlc_once_t *restrict once, void (*cb)(void *),
+ void *opaque);
-static inline void vlc_once_inline(vlc_once_t *restrict once, void (*cb)(void))
+static inline void vlc_once_inline(vlc_once_t *restrict once,
+ void (*cb)(void *), void *opaque)
{
/* Fast path: check if already initialized */
if (unlikely(atomic_load_explicit(&once->value, memory_order_acquire) < 3))
- vlc_once(once, cb);
+ vlc_once(once, cb, opaque);
}
-#define vlc_once(once, cb) vlc_once_inline(once, cb)
+#define vlc_once(once, cb, opaque) vlc_once_inline(once, cb, opaque)
#endif
/**
=====================================
modules/codec/gstreamer/gstdecode.c
=====================================
@@ -328,12 +328,13 @@ static gboolean vlc_gst_plugin_init( GstPlugin *p_plugin )
return TRUE;
}
-static bool vlc_gst_registered = false;
-static void vlc_gst_init_once(void)
+static void vlc_gst_init_once(void *data)
{
+ bool *registered = data;
+
gst_init( NULL, NULL );
- vlc_gst_registered = gst_plugin_register_static( 1, 0, "videolan",
+ *registered = gst_plugin_register_static( 1, 0, "videolan",
"VLC Gstreamer plugins", vlc_gst_plugin_init,
"1.0.0", "LGPL", "NA", "vlc", "NA" );
}
@@ -342,8 +343,9 @@ static void vlc_gst_init_once(void)
static bool vlc_gst_init( void )
{
static vlc_once_t once = VLC_STATIC_ONCE;
+ static bool vlc_gst_registered;
- vlc_once(&once, vlc_gst_init_once);
+ vlc_once(&once, vlc_gst_init_once, &vlc_gst_registered);
return vlc_gst_registered;
}
=====================================
modules/services_discovery/mtp.c
=====================================
@@ -79,6 +79,12 @@ typedef struct
vlc_thread_t thread;
} services_discovery_sys_t;
+static void vlc_libmtp_init(void *data)
+{
+ (void) data;
+ LIBMTP_Init();
+}
+
/*****************************************************************************
* Open: initialize and create stuff
*****************************************************************************/
@@ -95,7 +101,7 @@ static int Open( vlc_object_t *p_this )
static vlc_once_t mtp_init_once = VLC_STATIC_ONCE;
- vlc_once( &mtp_init_once, LIBMTP_Init );
+ vlc_once(&mtp_init_once, LIBMTP_Init, NULL);
if (vlc_clone (&p_sys->thread, Run, p_sd, VLC_THREAD_PRIORITY_LOW))
{
=====================================
src/misc/threads.c
=====================================
@@ -463,7 +463,7 @@ enum { VLC_ONCE_UNDONE, VLC_ONCE_DOING, VLC_ONCE_CONTEND, VLC_ONCE_DONE };
static_assert (VLC_ONCE_DONE == 3, "Check vlc_once in header file");
-void (vlc_once)(vlc_once_t *restrict once, void (*cb)(void))
+void (vlc_once)(vlc_once_t *restrict once, void (*cb)(void *), void *opaque)
{
unsigned int value = VLC_ONCE_UNDONE;
@@ -472,7 +472,7 @@ void (vlc_once)(vlc_once_t *restrict once, void (*cb)(void))
memory_order_acquire,
memory_order_acquire)) {
/* First time: run the callback */
- cb();
+ cb(opaque);
if (atomic_exchange_explicit(&once->value, VLC_ONCE_DONE,
memory_order_release) == VLC_ONCE_CONTEND)
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b18e2bf7c9bd3b99cf7dc756fa213d4c231f05e1...a747e30be3b7f8e92b62ff1948556a7247594f5a
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b18e2bf7c9bd3b99cf7dc756fa213d4c231f05e1...a747e30be3b7f8e92b62ff1948556a7247594f5a
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list