1be8d8537SStefan Hajnoczi /* 2be8d8537SStefan Hajnoczi * Event loop thread 3be8d8537SStefan Hajnoczi * 4be8d8537SStefan Hajnoczi * Copyright Red Hat Inc., 2013 5be8d8537SStefan Hajnoczi * 6be8d8537SStefan Hajnoczi * Authors: 7be8d8537SStefan Hajnoczi * Stefan Hajnoczi <stefanha@redhat.com> 8be8d8537SStefan Hajnoczi * 9be8d8537SStefan Hajnoczi * This work is licensed under the terms of the GNU GPL, version 2 or later. 10be8d8537SStefan Hajnoczi * See the COPYING file in the top-level directory. 11be8d8537SStefan Hajnoczi * 12be8d8537SStefan Hajnoczi */ 13be8d8537SStefan Hajnoczi 14be8d8537SStefan Hajnoczi #ifndef IOTHREAD_H 15be8d8537SStefan Hajnoczi #define IOTHREAD_H 16be8d8537SStefan Hajnoczi 17be8d8537SStefan Hajnoczi #include "block/aio.h" 188c2664d8SStefan Hajnoczi #include "qemu/thread.h" 19ec150c7eSMarkus Armbruster #include "qom/object.h" 207d5983e3SNicolas Saenz Julienne #include "sysemu/event-loop-base.h" 21be8d8537SStefan Hajnoczi 22be8d8537SStefan Hajnoczi #define TYPE_IOTHREAD "iothread" 23be8d8537SStefan Hajnoczi 24db1015e9SEduardo Habkost struct IOThread { 257d5983e3SNicolas Saenz Julienne EventLoopBase parent_obj; 268c2664d8SStefan Hajnoczi 278c2664d8SStefan Hajnoczi QemuThread thread; 288c2664d8SStefan Hajnoczi AioContext *ctx; 29b506e0f1SPeter Xu bool run_gcontext; /* whether we should run gcontext */ 30329163cbSWang Yong GMainContext *worker_context; 31329163cbSWang Yong GMainLoop *main_loop; 3221c4d15bSPeter Xu QemuSemaphore init_done_sem; /* is thread init done? */ 332362a28eSStefan Hajnoczi bool stopping; /* has iothread_stop() been called? */ 342362a28eSStefan Hajnoczi bool running; /* should iothread_run() continue? */ 358c2664d8SStefan Hajnoczi int thread_id; 360d9d86fbSStefan Hajnoczi 370d9d86fbSStefan Hajnoczi /* AioContext poll parameters */ 380d9d86fbSStefan Hajnoczi int64_t poll_max_ns; 395e5db499SStefan Hajnoczi int64_t poll_grow; 405e5db499SStefan Hajnoczi int64_t poll_shrink; 41db1015e9SEduardo Habkost }; 42db1015e9SEduardo Habkost typedef struct IOThread IOThread; 43be8d8537SStefan Hajnoczi 448110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, 458110fa1dSEduardo Habkost TYPE_IOTHREAD) 46be8d8537SStefan Hajnoczi 47be8d8537SStefan Hajnoczi char *iothread_get_id(IOThread *iothread); 48fbcc6923SStefan Hajnoczi IOThread *iothread_by_id(const char *id); 49be8d8537SStefan Hajnoczi AioContext *iothread_get_aio_context(IOThread *iothread); 50329163cbSWang Yong GMainContext *iothread_get_g_main_context(IOThread *iothread); 51be8d8537SStefan Hajnoczi 520173e21bSPeter Xu /* 530173e21bSPeter Xu * Helpers used to allocate iothreads for internal use. These 540173e21bSPeter Xu * iothreads will not be seen by monitor clients when query using 550173e21bSPeter Xu * "query-iothreads". 560173e21bSPeter Xu */ 570173e21bSPeter Xu IOThread *iothread_create(const char *id, Error **errp); 5882d90705SPeter Xu void iothread_stop(IOThread *iothread); 590173e21bSPeter Xu void iothread_destroy(IOThread *iothread); 600173e21bSPeter Xu 61ad22c308SElena Ufimtseva /* 62*a1a62cedSMichael Tokarev * Returns true if executing within IOThread context, 63ad22c308SElena Ufimtseva * false otherwise. 64ad22c308SElena Ufimtseva */ 65ad22c308SElena Ufimtseva bool qemu_in_iothread(void); 66ad22c308SElena Ufimtseva 67be8d8537SStefan Hajnoczi #endif /* IOTHREAD_H */ 68