mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
aio: introduce AioContext, move bottom halves there
Start introducing AioContext, which will let us remove globals from aio.c/async.c, and introduce multiple I/O threads. The bottom half functions now take an additional AioContext argument. A bottom half is created with a specific AioContext that remains the same throughout the lifetime. qemu_bh_new is just a wrapper that uses a global context. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
9958c351ee
commit
f627aab1cc
11 changed files with 119 additions and 72 deletions
30
async.c
30
async.c
|
@ -26,9 +26,6 @@
|
|||
#include "qemu-aio.h"
|
||||
#include "main-loop.h"
|
||||
|
||||
/* Anchor of the list of Bottom Halves belonging to the context */
|
||||
static struct QEMUBH *first_bh;
|
||||
|
||||
/***********************************************************/
|
||||
/* bottom halves (can be seen as timers which expire ASAP) */
|
||||
|
||||
|
@ -41,27 +38,26 @@ struct QEMUBH {
|
|||
bool deleted;
|
||||
};
|
||||
|
||||
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
|
||||
QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
|
||||
{
|
||||
QEMUBH *bh;
|
||||
bh = g_malloc0(sizeof(QEMUBH));
|
||||
bh->cb = cb;
|
||||
bh->opaque = opaque;
|
||||
bh->next = first_bh;
|
||||
first_bh = bh;
|
||||
bh->next = ctx->first_bh;
|
||||
ctx->first_bh = bh;
|
||||
return bh;
|
||||
}
|
||||
|
||||
int qemu_bh_poll(void)
|
||||
int aio_bh_poll(AioContext *ctx)
|
||||
{
|
||||
QEMUBH *bh, **bhp, *next;
|
||||
int ret;
|
||||
static int nesting = 0;
|
||||
|
||||
nesting++;
|
||||
ctx->walking_bh++;
|
||||
|
||||
ret = 0;
|
||||
for (bh = first_bh; bh; bh = next) {
|
||||
for (bh = ctx->first_bh; bh; bh = next) {
|
||||
next = bh->next;
|
||||
if (!bh->deleted && bh->scheduled) {
|
||||
bh->scheduled = 0;
|
||||
|
@ -72,11 +68,11 @@ int qemu_bh_poll(void)
|
|||
}
|
||||
}
|
||||
|
||||
nesting--;
|
||||
ctx->walking_bh--;
|
||||
|
||||
/* remove deleted bhs */
|
||||
if (!nesting) {
|
||||
bhp = &first_bh;
|
||||
if (!ctx->walking_bh) {
|
||||
bhp = &ctx->first_bh;
|
||||
while (*bhp) {
|
||||
bh = *bhp;
|
||||
if (bh->deleted) {
|
||||
|
@ -120,11 +116,11 @@ void qemu_bh_delete(QEMUBH *bh)
|
|||
bh->deleted = 1;
|
||||
}
|
||||
|
||||
void qemu_bh_update_timeout(uint32_t *timeout)
|
||||
void aio_bh_update_timeout(AioContext *ctx, uint32_t *timeout)
|
||||
{
|
||||
QEMUBH *bh;
|
||||
|
||||
for (bh = first_bh; bh; bh = bh->next) {
|
||||
for (bh = ctx->first_bh; bh; bh = bh->next) {
|
||||
if (!bh->deleted && bh->scheduled) {
|
||||
if (bh->idle) {
|
||||
/* idle bottom halves will be polled at least
|
||||
|
@ -140,3 +136,7 @@ void qemu_bh_update_timeout(uint32_t *timeout)
|
|||
}
|
||||
}
|
||||
|
||||
AioContext *aio_context_new(void)
|
||||
{
|
||||
return g_new0(AioContext, 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue