io: remove Error parameter from QIOTask thread worker

Now that task objects have a directly associated error,
there's no need for an an Error **errp parameter to
the QIOTask thread worker function. It already has a
QIOTask object, so can directly set the error on it.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2016-08-11 17:38:07 +01:00
parent 60e705c51c
commit 59de517d8d
4 changed files with 30 additions and 52 deletions

View File

@ -29,9 +29,8 @@ typedef struct QIOTask QIOTask;
typedef void (*QIOTaskFunc)(QIOTask *task,
gpointer opaque);
typedef int (*QIOTaskWorker)(QIOTask *task,
Error **errp,
gpointer opaque);
typedef void (*QIOTaskWorker)(QIOTask *task,
gpointer opaque);
/**
* QIOTask:
@ -163,18 +162,16 @@ typedef int (*QIOTaskWorker)(QIOTask *task,
* socket listen using QIOTask would require:
*
* <example>
* static int myobject_listen_worker(QIOTask *task,
* Error **errp,
* gpointer opaque)
* static void myobject_listen_worker(QIOTask *task,
* gpointer opaque)
* {
* QMyObject obj = QMY_OBJECT(qio_task_get_source(task));
* SocketAddress *addr = opaque;
* Error *err = NULL;
*
* obj->fd = socket_listen(addr, errp);
* if (obj->fd < 0) {
* return -1;
* }
* return 0;
* obj->fd = socket_listen(addr, &err);
*
qio_task_set_error(task, err);
* }
*
* void myobject_listen_async(QMyObject *obj,

View File

@ -156,19 +156,16 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc,
}
static int qio_channel_socket_connect_worker(QIOTask *task,
Error **errp,
gpointer opaque)
static void qio_channel_socket_connect_worker(QIOTask *task,
gpointer opaque)
{
QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
SocketAddress *addr = opaque;
int ret;
Error *err = NULL;
ret = qio_channel_socket_connect_sync(ioc,
addr,
errp);
qio_channel_socket_connect_sync(ioc, addr, &err);
return ret;
qio_task_set_error(task, err);
}
@ -218,19 +215,16 @@ int qio_channel_socket_listen_sync(QIOChannelSocket *ioc,
}
static int qio_channel_socket_listen_worker(QIOTask *task,
Error **errp,
gpointer opaque)
static void qio_channel_socket_listen_worker(QIOTask *task,
gpointer opaque)
{
QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
SocketAddress *addr = opaque;
int ret;
Error *err = NULL;
ret = qio_channel_socket_listen_sync(ioc,
addr,
errp);
qio_channel_socket_listen_sync(ioc, addr, &err);
return ret;
qio_task_set_error(task, err);
}
@ -293,21 +287,18 @@ static void qio_channel_socket_dgram_worker_free(gpointer opaque)
g_free(data);
}
static int qio_channel_socket_dgram_worker(QIOTask *task,
Error **errp,
gpointer opaque)
static void qio_channel_socket_dgram_worker(QIOTask *task,
gpointer opaque)
{
QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
struct QIOChannelSocketDGramWorkerData *data = opaque;
int ret;
Error *err = NULL;
/* socket_dgram() blocks in DNS lookups, so we must use a thread */
ret = qio_channel_socket_dgram_sync(ioc,
data->localAddr,
data->remoteAddr,
errp);
qio_channel_socket_dgram_sync(ioc, data->localAddr,
data->remoteAddr, &err);
return ret;
qio_task_set_error(task, err);
}

View File

@ -77,8 +77,6 @@ struct QIOTaskThreadData {
QIOTaskWorker worker;
gpointer opaque;
GDestroyNotify destroy;
Error *err;
int ret;
};
@ -87,9 +85,6 @@ static gboolean gio_task_thread_result(gpointer opaque)
struct QIOTaskThreadData *data = opaque;
trace_qio_task_thread_result(data->task);
if (data->err) {
qio_task_set_error(data->task, data->err);
}
qio_task_complete(data->task);
if (data->destroy) {
@ -107,10 +102,7 @@ static gpointer qio_task_thread_worker(gpointer opaque)
struct QIOTaskThreadData *data = opaque;
trace_qio_task_thread_run(data->task);
data->ret = data->worker(data->task, &data->err, data->opaque);
if (data->ret < 0 && data->err == NULL) {
error_setg(&data->err, "Task worker failed but did not set an error");
}
data->worker(data->task, data->opaque);
/* We're running in the background thread, and must only
* ever report the task results in the main event loop

View File

@ -140,20 +140,18 @@ struct TestThreadWorkerData {
GMainLoop *loop;
};
static int test_task_thread_worker(QIOTask *task,
Error **errp,
gpointer opaque)
static void test_task_thread_worker(QIOTask *task,
gpointer opaque)
{
struct TestThreadWorkerData *data = opaque;
data->worker = g_thread_self();
if (data->fail) {
error_setg(errp, "Testing fail");
return -1;
Error *err = NULL;
error_setg(&err, "Testing fail");
qio_task_set_error(task, err);
}
return 0;
}