mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 10:13:56 -06:00
qio: introduce qio_channel_add_watch_{full|source}
Firstly, introduce an internal qio_channel_add_watch_full(), which enhances qio_channel_add_watch() that context can be specified. Then add a new API wrapper qio_channel_add_watch_source() to return a GSource pointer rather than a tag ID. Note that the _source() call will keep a reference of GSource so that callers need to unref them explicitly when finished using the GSource. Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
7c28768fef
commit
315409c711
2 changed files with 78 additions and 6 deletions
40
io/channel.c
40
io/channel.c
|
@ -299,11 +299,12 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc,
|
|||
klass->io_set_aio_fd_handler(ioc, ctx, io_read, io_write, opaque);
|
||||
}
|
||||
|
||||
guint qio_channel_add_watch(QIOChannel *ioc,
|
||||
GIOCondition condition,
|
||||
QIOChannelFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify)
|
||||
guint qio_channel_add_watch_full(QIOChannel *ioc,
|
||||
GIOCondition condition,
|
||||
QIOChannelFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify,
|
||||
GMainContext *context)
|
||||
{
|
||||
GSource *source;
|
||||
guint id;
|
||||
|
@ -312,12 +313,39 @@ guint qio_channel_add_watch(QIOChannel *ioc,
|
|||
|
||||
g_source_set_callback(source, (GSourceFunc)func, user_data, notify);
|
||||
|
||||
id = g_source_attach(source, NULL);
|
||||
id = g_source_attach(source, context);
|
||||
g_source_unref(source);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
guint qio_channel_add_watch(QIOChannel *ioc,
|
||||
GIOCondition condition,
|
||||
QIOChannelFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
return qio_channel_add_watch_full(ioc, condition, func,
|
||||
user_data, notify, NULL);
|
||||
}
|
||||
|
||||
GSource *qio_channel_add_watch_source(QIOChannel *ioc,
|
||||
GIOCondition condition,
|
||||
QIOChannelFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify,
|
||||
GMainContext *context)
|
||||
{
|
||||
GSource *source;
|
||||
guint id;
|
||||
|
||||
id = qio_channel_add_watch_full(ioc, condition, func,
|
||||
user_data, notify, context);
|
||||
source = g_main_context_find_source_by_id(context, id);
|
||||
g_source_ref(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
|
||||
int qio_channel_shutdown(QIOChannel *ioc,
|
||||
QIOChannelShutdown how,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue