mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-31 13:24:13 +02:00
Add g_source_set_dispose_function() for setting a dispose function for GSource
This allows GSource implementors to safely clear any other references to the GSource while the GSource is still valid, unlike when doing the same from the finalize function. After the dispose function has run, it is valid for the reference count of the GSource to be > 0 again to allow the case where another thread in the mean-time got access to the GSource reference before the dispose function was called. This allows fixing a thread-safety issue in the GCancellable, GstBus and various other GSource implementations.
This commit is contained in:
21
glib/gmain.h
21
glib/gmain.h
@@ -204,6 +204,20 @@ typedef gboolean (*GSourceFunc) (gpointer user_data);
|
||||
typedef void (*GChildWatchFunc) (GPid pid,
|
||||
gint status,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
/**
|
||||
* GSourceDisposeFunc:
|
||||
* @source: #GSource that is currently being disposed
|
||||
*
|
||||
* Dispose function for @source. See g_source_set_dispose_function() for
|
||||
* details.
|
||||
*
|
||||
* Since: 2.64
|
||||
*/
|
||||
GLIB_AVAILABLE_TYPE_IN_2_64
|
||||
typedef void (*GSourceDisposeFunc) (GSource *source);
|
||||
|
||||
struct _GSource
|
||||
{
|
||||
/*< private >*/
|
||||
@@ -536,6 +550,13 @@ GMainContext *g_main_loop_get_context (GMainLoop *loop);
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
GSource *g_source_new (GSourceFuncs *source_funcs,
|
||||
guint struct_size);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
GLIB_AVAILABLE_IN_2_64
|
||||
void g_source_set_dispose_function (GSource *source,
|
||||
GSourceDisposeFunc dispose);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
GSource *g_source_ref (GSource *source);
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
|
Reference in New Issue
Block a user