xref: /openbmc/qemu/include/sysemu/iothread.h (revision 8f0a3716)
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 
20 #define TYPE_IOTHREAD "iothread"
21 
22 typedef struct {
23     Object parent_obj;
24 
25     QemuThread thread;
26     AioContext *ctx;
27     GMainContext *worker_context;
28     GMainLoop *main_loop;
29     GOnce once;
30     QemuMutex init_done_lock;
31     QemuCond init_done_cond;    /* is thread initialization done? */
32     bool stopping;              /* has iothread_stop() been called? */
33     bool running;               /* should iothread_run() continue? */
34     int thread_id;
35 
36     /* AioContext poll parameters */
37     int64_t poll_max_ns;
38     int64_t poll_grow;
39     int64_t poll_shrink;
40 } IOThread;
41 
42 #define IOTHREAD(obj) \
43    OBJECT_CHECK(IOThread, obj, TYPE_IOTHREAD)
44 
45 char *iothread_get_id(IOThread *iothread);
46 IOThread *iothread_by_id(const char *id);
47 AioContext *iothread_get_aio_context(IOThread *iothread);
48 void iothread_stop_all(void);
49 GMainContext *iothread_get_g_main_context(IOThread *iothread);
50 
51 /*
52  * Helpers used to allocate iothreads for internal use.  These
53  * iothreads will not be seen by monitor clients when query using
54  * "query-iothreads".
55  */
56 IOThread *iothread_create(const char *id, Error **errp);
57 void iothread_stop(IOThread *iothread);
58 void iothread_destroy(IOThread *iothread);
59 
60 #endif /* IOTHREAD_H */
61