xref: /openbmc/qemu/include/sysemu/iothread.h (revision e4082063)
1 /*
2  * Event loop thread
3  *
4  * Copyright Red Hat Inc., 2013
5  *
6  * Authors:
7  *  Stefan Hajnoczi   <stefanha@redhat.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  *
12  */
13 
14 #ifndef IOTHREAD_H
15 #define IOTHREAD_H
16 
17 #include "block/aio.h"
18 #include "qemu/thread.h"
19 #include "qom/object.h"
20 #include "sysemu/event-loop-base.h"
21 
22 #define TYPE_IOTHREAD "iothread"
23 
24 struct IOThread {
25     EventLoopBase parent_obj;
26 
27     QemuThread thread;
28     AioContext *ctx;
29     bool run_gcontext;          /* whether we should run gcontext */
30     GMainContext *worker_context;
31     GMainLoop *main_loop;
32     QemuSemaphore init_done_sem; /* is thread init done? */
33     bool stopping;              /* has iothread_stop() been called? */
34     bool running;               /* should iothread_run() continue? */
35     int thread_id;
36 
37     /* AioContext poll parameters */
38     int64_t poll_max_ns;
39     int64_t poll_grow;
40     int64_t poll_shrink;
41 };
42 typedef struct IOThread IOThread;
43 
44 DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD,
45                          TYPE_IOTHREAD)
46 
47 char *iothread_get_id(IOThread *iothread);
48 IOThread *iothread_by_id(const char *id);
49 AioContext *iothread_get_aio_context(IOThread *iothread);
50 GMainContext *iothread_get_g_main_context(IOThread *iothread);
51 
52 /*
53  * Helpers used to allocate iothreads for internal use.  These
54  * iothreads will not be seen by monitor clients when query using
55  * "query-iothreads".
56  */
57 IOThread *iothread_create(const char *id, Error **errp);
58 void iothread_stop(IOThread *iothread);
59 void iothread_destroy(IOThread *iothread);
60 
61 /*
62  * Returns true if executing withing IOThread context,
63  * false otherwise.
64  */
65 bool qemu_in_iothread(void);
66 
67 #endif /* IOTHREAD_H */
68