In existing code we create the gcontext dynamically at the first access of the gcontext from caller. That can bring some complexity and potential races during using iothread. Since the context itself is not that big a resource, and we won't have millions of iothread, let's simply create the gcontext unconditionally. This will also be a preparation work further to move the thread context push operation earlier than before (now it's only pushed right before we want to start running the gmainloop). Removing the g_once since it's not necessary, while introducing a new run_gcontext boolean to show whether we want to run the gcontext. Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-id: 20190306115532.23025-3-peterx@redhat.com Message-Id: <20190306115532.23025-3-peterx@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
59 lines
1.5 KiB
C
59 lines
1.5 KiB
C
/*
|
|
* Event loop thread
|
|
*
|
|
* Copyright Red Hat Inc., 2013
|
|
*
|
|
* Authors:
|
|
* Stefan Hajnoczi <stefanha@redhat.com>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*
|
|
*/
|
|
|
|
#ifndef IOTHREAD_H
|
|
#define IOTHREAD_H
|
|
|
|
#include "block/aio.h"
|
|
#include "qemu/thread.h"
|
|
|
|
#define TYPE_IOTHREAD "iothread"
|
|
|
|
typedef struct {
|
|
Object parent_obj;
|
|
|
|
QemuThread thread;
|
|
AioContext *ctx;
|
|
bool run_gcontext; /* whether we should run gcontext */
|
|
GMainContext *worker_context;
|
|
GMainLoop *main_loop;
|
|
QemuSemaphore init_done_sem; /* is thread init done? */
|
|
bool stopping; /* has iothread_stop() been called? */
|
|
bool running; /* should iothread_run() continue? */
|
|
int thread_id;
|
|
|
|
/* AioContext poll parameters */
|
|
int64_t poll_max_ns;
|
|
int64_t poll_grow;
|
|
int64_t poll_shrink;
|
|
} IOThread;
|
|
|
|
#define IOTHREAD(obj) \
|
|
OBJECT_CHECK(IOThread, obj, TYPE_IOTHREAD)
|
|
|
|
char *iothread_get_id(IOThread *iothread);
|
|
IOThread *iothread_by_id(const char *id);
|
|
AioContext *iothread_get_aio_context(IOThread *iothread);
|
|
GMainContext *iothread_get_g_main_context(IOThread *iothread);
|
|
|
|
/*
|
|
* Helpers used to allocate iothreads for internal use. These
|
|
* iothreads will not be seen by monitor clients when query using
|
|
* "query-iothreads".
|
|
*/
|
|
IOThread *iothread_create(const char *id, Error **errp);
|
|
void iothread_stop(IOThread *iothread);
|
|
void iothread_destroy(IOThread *iothread);
|
|
|
|
#endif /* IOTHREAD_H */
|