mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-02 13:53:06 +02:00
gdbusprivate: Improve ownership docs for write_message_async()
The ownership transfers in this code are a bit complex, so adding some extra documentation and `g_steal_pointer()` calls should hopefully help clarify things. This doesn’t introduce any functional changes, just code documentation. Another drive-by improvement in the quest for #1264. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Helps: #1264
This commit is contained in:
parent
861741ef4b
commit
d7c813cf5b
@ -919,13 +919,14 @@ static void write_message_continue_writing (MessageToWriteData *data);
|
|||||||
*
|
*
|
||||||
* write-lock is not held on entry
|
* write-lock is not held on entry
|
||||||
* output_pending is PENDING_WRITE on entry
|
* output_pending is PENDING_WRITE on entry
|
||||||
|
* @user_data is (transfer full)
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
write_message_async_cb (GObject *source_object,
|
write_message_async_cb (GObject *source_object,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MessageToWriteData *data = user_data;
|
MessageToWriteData *data = g_steal_pointer (&user_data);
|
||||||
gssize bytes_written;
|
gssize bytes_written;
|
||||||
GError *error;
|
GError *error;
|
||||||
|
|
||||||
@ -960,7 +961,7 @@ write_message_async_cb (GObject *source_object,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_message_continue_writing (data);
|
write_message_continue_writing (g_steal_pointer (&data));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
;
|
;
|
||||||
@ -977,8 +978,8 @@ on_socket_ready (GSocket *socket,
|
|||||||
GIOCondition condition,
|
GIOCondition condition,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MessageToWriteData *data = user_data;
|
MessageToWriteData *data = g_steal_pointer (&user_data);
|
||||||
write_message_continue_writing (data);
|
write_message_continue_writing (g_steal_pointer (&data));
|
||||||
return FALSE; /* remove source */
|
return FALSE; /* remove source */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -987,6 +988,7 @@ on_socket_ready (GSocket *socket,
|
|||||||
*
|
*
|
||||||
* write-lock is not held on entry
|
* write-lock is not held on entry
|
||||||
* output_pending is PENDING_WRITE on entry
|
* output_pending is PENDING_WRITE on entry
|
||||||
|
* @data is (transfer full)
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
write_message_continue_writing (MessageToWriteData *data)
|
write_message_continue_writing (MessageToWriteData *data)
|
||||||
@ -1064,7 +1066,7 @@ write_message_continue_writing (MessageToWriteData *data)
|
|||||||
data->worker->cancellable);
|
data->worker->cancellable);
|
||||||
g_source_set_callback (source,
|
g_source_set_callback (source,
|
||||||
(GSourceFunc) on_socket_ready,
|
(GSourceFunc) on_socket_ready,
|
||||||
data,
|
g_steal_pointer (&data),
|
||||||
NULL); /* GDestroyNotify */
|
NULL); /* GDestroyNotify */
|
||||||
g_source_attach (source, g_main_context_get_thread_default ());
|
g_source_attach (source, g_main_context_get_thread_default ());
|
||||||
g_source_unref (source);
|
g_source_unref (source);
|
||||||
@ -1093,7 +1095,7 @@ write_message_continue_writing (MessageToWriteData *data)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_message_continue_writing (data);
|
write_message_continue_writing (g_steal_pointer (&data));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
@ -1121,7 +1123,7 @@ write_message_continue_writing (MessageToWriteData *data)
|
|||||||
G_PRIORITY_DEFAULT,
|
G_PRIORITY_DEFAULT,
|
||||||
data->worker->cancellable,
|
data->worker->cancellable,
|
||||||
write_message_async_cb,
|
write_message_async_cb,
|
||||||
data);
|
data); /* steal @data */
|
||||||
}
|
}
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
out:
|
out:
|
||||||
@ -1144,7 +1146,7 @@ write_message_async (GDBusWorker *worker,
|
|||||||
g_task_set_source_tag (data->task, write_message_async);
|
g_task_set_source_tag (data->task, write_message_async);
|
||||||
g_task_set_name (data->task, "[gio] D-Bus write message");
|
g_task_set_name (data->task, "[gio] D-Bus write message");
|
||||||
data->total_written = 0;
|
data->total_written = 0;
|
||||||
write_message_continue_writing (data);
|
write_message_continue_writing (g_steal_pointer (&data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called in private thread shared by all GDBusConnection instances (with write-lock held) */
|
/* called in private thread shared by all GDBusConnection instances (with write-lock held) */
|
||||||
@ -1333,6 +1335,7 @@ prepare_flush_unlocked (GDBusWorker *worker)
|
|||||||
*
|
*
|
||||||
* write-lock is not held on entry
|
* write-lock is not held on entry
|
||||||
* output_pending is PENDING_WRITE on entry
|
* output_pending is PENDING_WRITE on entry
|
||||||
|
* @user_data is (transfer full)
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
write_message_cb (GObject *source_object,
|
write_message_cb (GObject *source_object,
|
||||||
@ -1551,7 +1554,7 @@ continue_writing (GDBusWorker *worker)
|
|||||||
write_message_async (worker,
|
write_message_async (worker,
|
||||||
data,
|
data,
|
||||||
write_message_cb,
|
write_message_cb,
|
||||||
data);
|
data); /* takes ownership of @data as user_data */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user