]>
Commit | Line | Data |
---|---|---|
4f999d05 | 1 | /* |
c2b38b27 | 2 | * Data plane event loop |
4f999d05 KW |
3 | * |
4 | * Copyright (c) 2003-2008 Fabrice Bellard | |
c2b38b27 | 5 | * Copyright (c) 2009-2017 QEMU contributors |
4f999d05 KW |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
23 | * THE SOFTWARE. | |
24 | */ | |
25 | ||
d38ea87a | 26 | #include "qemu/osdep.h" |
da34e65c | 27 | #include "qapi/error.h" |
737e150e | 28 | #include "block/aio.h" |
9b34277d | 29 | #include "block/thread-pool.h" |
1de7afc9 | 30 | #include "qemu/main-loop.h" |
0ceb849b | 31 | #include "qemu/atomic.h" |
0187f5c9 | 32 | #include "block/raw-aio.h" |
0c330a73 PB |
33 | #include "qemu/coroutine_int.h" |
34 | #include "trace.h" | |
9a1e9481 | 35 | |
4f999d05 KW |
36 | /***********************************************************/ |
37 | /* bottom halves (can be seen as timers which expire ASAP) */ | |
38 | ||
39 | struct QEMUBH { | |
2f4dc3c1 | 40 | AioContext *ctx; |
4f999d05 KW |
41 | QEMUBHFunc *cb; |
42 | void *opaque; | |
4f999d05 | 43 | QEMUBH *next; |
9b47b17e SW |
44 | bool scheduled; |
45 | bool idle; | |
46 | bool deleted; | |
4f999d05 KW |
47 | }; |
48 | ||
5b8bb359 PB |
49 | void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque) |
50 | { | |
51 | QEMUBH *bh; | |
52 | bh = g_new(QEMUBH, 1); | |
53 | *bh = (QEMUBH){ | |
54 | .ctx = ctx, | |
55 | .cb = cb, | |
56 | .opaque = opaque, | |
57 | }; | |
d7c99a12 | 58 | qemu_lockcnt_lock(&ctx->list_lock); |
5b8bb359 PB |
59 | bh->next = ctx->first_bh; |
60 | bh->scheduled = 1; | |
61 | bh->deleted = 1; | |
62 | /* Make sure that the members are ready before putting bh into list */ | |
63 | smp_wmb(); | |
64 | ctx->first_bh = bh; | |
d7c99a12 | 65 | qemu_lockcnt_unlock(&ctx->list_lock); |
c9d1a561 | 66 | aio_notify(ctx); |
5b8bb359 PB |
67 | } |
68 | ||
f627aab1 | 69 | QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque) |
4f999d05 KW |
70 | { |
71 | QEMUBH *bh; | |
ee82310f PB |
72 | bh = g_new(QEMUBH, 1); |
73 | *bh = (QEMUBH){ | |
74 | .ctx = ctx, | |
75 | .cb = cb, | |
76 | .opaque = opaque, | |
77 | }; | |
d7c99a12 | 78 | qemu_lockcnt_lock(&ctx->list_lock); |
f627aab1 | 79 | bh->next = ctx->first_bh; |
dcc772e2 LPF |
80 | /* Make sure that the members are ready before putting bh into list */ |
81 | smp_wmb(); | |
f627aab1 | 82 | ctx->first_bh = bh; |
d7c99a12 | 83 | qemu_lockcnt_unlock(&ctx->list_lock); |
4f999d05 KW |
84 | return bh; |
85 | } | |
86 | ||
df281b80 PD |
87 | void aio_bh_call(QEMUBH *bh) |
88 | { | |
89 | bh->cb(bh->opaque); | |
90 | } | |
91 | ||
bd451435 PB |
92 | /* Multiple occurrences of aio_bh_poll cannot be called concurrently. |
93 | * The count in ctx->list_lock is incremented before the call, and is | |
94 | * not affected by the call. | |
95 | */ | |
f627aab1 | 96 | int aio_bh_poll(AioContext *ctx) |
4f999d05 | 97 | { |
7887f620 | 98 | QEMUBH *bh, **bhp, *next; |
4f999d05 | 99 | int ret; |
7d506c90 | 100 | bool deleted = false; |
648fb0ea | 101 | |
4f999d05 | 102 | ret = 0; |
d7c99a12 PB |
103 | for (bh = atomic_rcu_read(&ctx->first_bh); bh; bh = next) { |
104 | next = atomic_rcu_read(&bh->next); | |
e8d3b1a2 PB |
105 | /* The atomic_xchg is paired with the one in qemu_bh_schedule. The |
106 | * implicit memory barrier ensures that the callback sees all writes | |
107 | * done by the scheduling thread. It also ensures that the scheduling | |
108 | * thread sees the zero before bh->cb has run, and thus will call | |
109 | * aio_notify again if necessary. | |
110 | */ | |
5b8bb359 | 111 | if (atomic_xchg(&bh->scheduled, 0)) { |
65c1b5b6 PB |
112 | /* Idle BHs don't count as progress */ |
113 | if (!bh->idle) { | |
4f999d05 | 114 | ret = 1; |
ca96ac44 | 115 | } |
4f999d05 | 116 | bh->idle = 0; |
df281b80 | 117 | aio_bh_call(bh); |
4f999d05 | 118 | } |
7d506c90 PB |
119 | if (bh->deleted) { |
120 | deleted = true; | |
121 | } | |
4f999d05 KW |
122 | } |
123 | ||
124 | /* remove deleted bhs */ | |
7d506c90 | 125 | if (!deleted) { |
7d506c90 PB |
126 | return ret; |
127 | } | |
128 | ||
bd451435 | 129 | if (qemu_lockcnt_dec_if_lock(&ctx->list_lock)) { |
f627aab1 | 130 | bhp = &ctx->first_bh; |
648fb0ea KW |
131 | while (*bhp) { |
132 | bh = *bhp; | |
5b8bb359 | 133 | if (bh->deleted && !bh->scheduled) { |
648fb0ea KW |
134 | *bhp = bh->next; |
135 | g_free(bh); | |
136 | } else { | |
137 | bhp = &bh->next; | |
138 | } | |
139 | } | |
bd451435 | 140 | qemu_lockcnt_inc_and_unlock(&ctx->list_lock); |
4f999d05 | 141 | } |
4f999d05 KW |
142 | return ret; |
143 | } | |
144 | ||
145 | void qemu_bh_schedule_idle(QEMUBH *bh) | |
146 | { | |
4f999d05 | 147 | bh->idle = 1; |
dcc772e2 LPF |
148 | /* Make sure that idle & any writes needed by the callback are done |
149 | * before the locations are read in the aio_bh_poll. | |
150 | */ | |
e8d3b1a2 | 151 | atomic_mb_set(&bh->scheduled, 1); |
4f999d05 KW |
152 | } |
153 | ||
154 | void qemu_bh_schedule(QEMUBH *bh) | |
155 | { | |
924fe129 SH |
156 | AioContext *ctx; |
157 | ||
924fe129 | 158 | ctx = bh->ctx; |
4f999d05 | 159 | bh->idle = 0; |
e8d3b1a2 | 160 | /* The memory barrier implicit in atomic_xchg makes sure that: |
924fe129 SH |
161 | * 1. idle & any writes needed by the callback are done before the |
162 | * locations are read in the aio_bh_poll. | |
163 | * 2. ctx is loaded before scheduled is set and the callback has a chance | |
164 | * to execute. | |
dcc772e2 | 165 | */ |
e8d3b1a2 PB |
166 | if (atomic_xchg(&bh->scheduled, 1) == 0) { |
167 | aio_notify(ctx); | |
168 | } | |
4f999d05 KW |
169 | } |
170 | ||
dcc772e2 LPF |
171 | |
172 | /* This func is async. | |
173 | */ | |
4f999d05 KW |
174 | void qemu_bh_cancel(QEMUBH *bh) |
175 | { | |
ef6dada8 | 176 | atomic_mb_set(&bh->scheduled, 0); |
4f999d05 KW |
177 | } |
178 | ||
dcc772e2 LPF |
179 | /* This func is async.The bottom half will do the delete action at the finial |
180 | * end. | |
181 | */ | |
4f999d05 KW |
182 | void qemu_bh_delete(QEMUBH *bh) |
183 | { | |
184 | bh->scheduled = 0; | |
185 | bh->deleted = 1; | |
186 | } | |
187 | ||
845ca10d PB |
188 | int64_t |
189 | aio_compute_timeout(AioContext *ctx) | |
4f999d05 | 190 | { |
845ca10d PB |
191 | int64_t deadline; |
192 | int timeout = -1; | |
4f999d05 KW |
193 | QEMUBH *bh; |
194 | ||
d7c99a12 PB |
195 | for (bh = atomic_rcu_read(&ctx->first_bh); bh; |
196 | bh = atomic_rcu_read(&bh->next)) { | |
5b8bb359 | 197 | if (bh->scheduled) { |
4f999d05 KW |
198 | if (bh->idle) { |
199 | /* idle bottom halves will be polled at least | |
200 | * every 10ms */ | |
845ca10d | 201 | timeout = 10000000; |
4f999d05 KW |
202 | } else { |
203 | /* non-idle bottom halves will be executed | |
204 | * immediately */ | |
845ca10d | 205 | return 0; |
4f999d05 KW |
206 | } |
207 | } | |
208 | } | |
e3713e00 | 209 | |
845ca10d | 210 | deadline = timerlistgroup_deadline_ns(&ctx->tlg); |
533a8cf3 | 211 | if (deadline == 0) { |
845ca10d | 212 | return 0; |
533a8cf3 | 213 | } else { |
845ca10d | 214 | return qemu_soonest_timeout(timeout, deadline); |
533a8cf3 | 215 | } |
845ca10d | 216 | } |
533a8cf3 | 217 | |
845ca10d PB |
218 | static gboolean |
219 | aio_ctx_prepare(GSource *source, gint *timeout) | |
220 | { | |
221 | AioContext *ctx = (AioContext *) source; | |
222 | ||
eabc9779 PB |
223 | atomic_or(&ctx->notify_me, 1); |
224 | ||
845ca10d PB |
225 | /* We assume there is no timeout already supplied */ |
226 | *timeout = qemu_timeout_ns_to_ms(aio_compute_timeout(ctx)); | |
a3462c65 PB |
227 | |
228 | if (aio_prepare(ctx)) { | |
229 | *timeout = 0; | |
230 | } | |
231 | ||
845ca10d | 232 | return *timeout == 0; |
e3713e00 PB |
233 | } |
234 | ||
235 | static gboolean | |
236 | aio_ctx_check(GSource *source) | |
237 | { | |
238 | AioContext *ctx = (AioContext *) source; | |
239 | QEMUBH *bh; | |
240 | ||
eabc9779 | 241 | atomic_and(&ctx->notify_me, ~1); |
05e514b1 | 242 | aio_notify_accept(ctx); |
21a03d17 | 243 | |
e3713e00 | 244 | for (bh = ctx->first_bh; bh; bh = bh->next) { |
5b8bb359 | 245 | if (bh->scheduled) { |
e3713e00 | 246 | return true; |
6977d901 | 247 | } |
e3713e00 | 248 | } |
533a8cf3 | 249 | return aio_pending(ctx) || (timerlistgroup_deadline_ns(&ctx->tlg) == 0); |
e3713e00 PB |
250 | } |
251 | ||
252 | static gboolean | |
253 | aio_ctx_dispatch(GSource *source, | |
254 | GSourceFunc callback, | |
255 | gpointer user_data) | |
256 | { | |
257 | AioContext *ctx = (AioContext *) source; | |
258 | ||
259 | assert(callback == NULL); | |
a153bf52 | 260 | aio_dispatch(ctx); |
e3713e00 PB |
261 | return true; |
262 | } | |
263 | ||
2f4dc3c1 PB |
264 | static void |
265 | aio_ctx_finalize(GSource *source) | |
266 | { | |
267 | AioContext *ctx = (AioContext *) source; | |
268 | ||
9b34277d | 269 | thread_pool_free(ctx->thread_pool); |
a076972a | 270 | |
0187f5c9 PB |
271 | #ifdef CONFIG_LINUX_AIO |
272 | if (ctx->linux_aio) { | |
273 | laio_detach_aio_context(ctx->linux_aio, ctx); | |
274 | laio_cleanup(ctx->linux_aio); | |
275 | ctx->linux_aio = NULL; | |
276 | } | |
277 | #endif | |
278 | ||
0c330a73 PB |
279 | assert(QSLIST_EMPTY(&ctx->scheduled_coroutines)); |
280 | qemu_bh_delete(ctx->co_schedule_bh); | |
281 | ||
d7c99a12 PB |
282 | qemu_lockcnt_lock(&ctx->list_lock); |
283 | assert(!qemu_lockcnt_count(&ctx->list_lock)); | |
a076972a SH |
284 | while (ctx->first_bh) { |
285 | QEMUBH *next = ctx->first_bh->next; | |
286 | ||
287 | /* qemu_bh_delete() must have been called on BHs in this AioContext */ | |
288 | assert(ctx->first_bh->deleted); | |
289 | ||
290 | g_free(ctx->first_bh); | |
291 | ctx->first_bh = next; | |
292 | } | |
d7c99a12 | 293 | qemu_lockcnt_unlock(&ctx->list_lock); |
a076972a | 294 | |
f6a51c84 | 295 | aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL); |
2f4dc3c1 | 296 | event_notifier_cleanup(&ctx->notifier); |
3fe71223 | 297 | qemu_rec_mutex_destroy(&ctx->lock); |
d7c99a12 | 298 | qemu_lockcnt_destroy(&ctx->list_lock); |
dae21b98 | 299 | timerlistgroup_deinit(&ctx->tlg); |
cd0a6d2b | 300 | aio_context_destroy(ctx); |
2f4dc3c1 PB |
301 | } |
302 | ||
e3713e00 PB |
303 | static GSourceFuncs aio_source_funcs = { |
304 | aio_ctx_prepare, | |
305 | aio_ctx_check, | |
306 | aio_ctx_dispatch, | |
2f4dc3c1 | 307 | aio_ctx_finalize |
e3713e00 PB |
308 | }; |
309 | ||
310 | GSource *aio_get_g_source(AioContext *ctx) | |
311 | { | |
312 | g_source_ref(&ctx->source); | |
313 | return &ctx->source; | |
314 | } | |
a915f4bc | 315 | |
9b34277d SH |
316 | ThreadPool *aio_get_thread_pool(AioContext *ctx) |
317 | { | |
318 | if (!ctx->thread_pool) { | |
319 | ctx->thread_pool = thread_pool_new(ctx); | |
320 | } | |
321 | return ctx->thread_pool; | |
322 | } | |
323 | ||
0187f5c9 | 324 | #ifdef CONFIG_LINUX_AIO |
ed6e2161 | 325 | LinuxAioState *aio_setup_linux_aio(AioContext *ctx, Error **errp) |
0187f5c9 PB |
326 | { |
327 | if (!ctx->linux_aio) { | |
ed6e2161 NA |
328 | ctx->linux_aio = laio_init(errp); |
329 | if (ctx->linux_aio) { | |
330 | laio_attach_aio_context(ctx->linux_aio, ctx); | |
331 | } | |
0187f5c9 PB |
332 | } |
333 | return ctx->linux_aio; | |
334 | } | |
ed6e2161 NA |
335 | |
336 | LinuxAioState *aio_get_linux_aio(AioContext *ctx) | |
337 | { | |
338 | assert(ctx->linux_aio); | |
339 | return ctx->linux_aio; | |
340 | } | |
0187f5c9 PB |
341 | #endif |
342 | ||
2f4dc3c1 PB |
343 | void aio_notify(AioContext *ctx) |
344 | { | |
eabc9779 PB |
345 | /* Write e.g. bh->scheduled before reading ctx->notify_me. Pairs |
346 | * with atomic_or in aio_ctx_prepare or atomic_add in aio_poll. | |
347 | */ | |
0ceb849b | 348 | smp_mb(); |
eabc9779 | 349 | if (ctx->notify_me) { |
0ceb849b | 350 | event_notifier_set(&ctx->notifier); |
05e514b1 PB |
351 | atomic_mb_set(&ctx->notified, true); |
352 | } | |
353 | } | |
354 | ||
355 | void aio_notify_accept(AioContext *ctx) | |
356 | { | |
873df2ce MAL |
357 | if (atomic_xchg(&ctx->notified, false) |
358 | #ifdef WIN32 | |
359 | || true | |
360 | #endif | |
361 | ) { | |
05e514b1 | 362 | event_notifier_test_and_clear(&ctx->notifier); |
0ceb849b | 363 | } |
2f4dc3c1 PB |
364 | } |
365 | ||
3f53bc61 | 366 | static void aio_timerlist_notify(void *opaque, QEMUClockType type) |
d5541d86 AB |
367 | { |
368 | aio_notify(opaque); | |
369 | } | |
370 | ||
21a03d17 PB |
371 | static void event_notifier_dummy_cb(EventNotifier *e) |
372 | { | |
373 | } | |
374 | ||
4a1cba38 SH |
375 | /* Returns true if aio_notify() was called (e.g. a BH was scheduled) */ |
376 | static bool event_notifier_poll(void *opaque) | |
377 | { | |
378 | EventNotifier *e = opaque; | |
379 | AioContext *ctx = container_of(e, AioContext, notifier); | |
380 | ||
381 | return atomic_read(&ctx->notified); | |
382 | } | |
383 | ||
0c330a73 PB |
384 | static void co_schedule_bh_cb(void *opaque) |
385 | { | |
386 | AioContext *ctx = opaque; | |
387 | QSLIST_HEAD(, Coroutine) straight, reversed; | |
388 | ||
389 | QSLIST_MOVE_ATOMIC(&reversed, &ctx->scheduled_coroutines); | |
390 | QSLIST_INIT(&straight); | |
391 | ||
392 | while (!QSLIST_EMPTY(&reversed)) { | |
393 | Coroutine *co = QSLIST_FIRST(&reversed); | |
394 | QSLIST_REMOVE_HEAD(&reversed, co_scheduled_next); | |
395 | QSLIST_INSERT_HEAD(&straight, co, co_scheduled_next); | |
396 | } | |
397 | ||
398 | while (!QSLIST_EMPTY(&straight)) { | |
399 | Coroutine *co = QSLIST_FIRST(&straight); | |
400 | QSLIST_REMOVE_HEAD(&straight, co_scheduled_next); | |
401 | trace_aio_co_schedule_bh_cb(ctx, co); | |
1919631e | 402 | aio_context_acquire(ctx); |
6133b39f JC |
403 | |
404 | /* Protected by write barrier in qemu_aio_coroutine_enter */ | |
405 | atomic_set(&co->scheduled, NULL); | |
6808ae04 | 406 | qemu_aio_coroutine_enter(ctx, co); |
1919631e | 407 | aio_context_release(ctx); |
0c330a73 PB |
408 | } |
409 | } | |
410 | ||
2f78e491 | 411 | AioContext *aio_context_new(Error **errp) |
f627aab1 | 412 | { |
2f78e491 | 413 | int ret; |
2f4dc3c1 | 414 | AioContext *ctx; |
37fcee5d | 415 | |
2f4dc3c1 | 416 | ctx = (AioContext *) g_source_new(&aio_source_funcs, sizeof(AioContext)); |
7e003465 C |
417 | aio_context_setup(ctx); |
418 | ||
2f78e491 CN |
419 | ret = event_notifier_init(&ctx->notifier, false); |
420 | if (ret < 0) { | |
2f78e491 | 421 | error_setg_errno(errp, -ret, "Failed to initialize event notifier"); |
37fcee5d | 422 | goto fail; |
2f78e491 | 423 | } |
fcf5def1 | 424 | g_source_set_can_recurse(&ctx->source, true); |
d7c99a12 | 425 | qemu_lockcnt_init(&ctx->list_lock); |
0c330a73 PB |
426 | |
427 | ctx->co_schedule_bh = aio_bh_new(ctx, co_schedule_bh_cb, ctx); | |
428 | QSLIST_INIT(&ctx->scheduled_coroutines); | |
429 | ||
2f78e491 | 430 | aio_set_event_notifier(ctx, &ctx->notifier, |
dca21ef2 | 431 | false, |
f6a51c84 | 432 | event_notifier_dummy_cb, |
4a1cba38 | 433 | event_notifier_poll); |
0187f5c9 PB |
434 | #ifdef CONFIG_LINUX_AIO |
435 | ctx->linux_aio = NULL; | |
436 | #endif | |
9b34277d | 437 | ctx->thread_pool = NULL; |
3fe71223 | 438 | qemu_rec_mutex_init(&ctx->lock); |
d5541d86 | 439 | timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx); |
2f4dc3c1 | 440 | |
82a41186 | 441 | ctx->poll_ns = 0; |
4a1cba38 | 442 | ctx->poll_max_ns = 0; |
82a41186 SH |
443 | ctx->poll_grow = 0; |
444 | ctx->poll_shrink = 0; | |
4a1cba38 | 445 | |
2f4dc3c1 | 446 | return ctx; |
37fcee5d FZ |
447 | fail: |
448 | g_source_destroy(&ctx->source); | |
449 | return NULL; | |
e3713e00 PB |
450 | } |
451 | ||
0c330a73 PB |
452 | void aio_co_schedule(AioContext *ctx, Coroutine *co) |
453 | { | |
454 | trace_aio_co_schedule(ctx, co); | |
6133b39f JC |
455 | const char *scheduled = atomic_cmpxchg(&co->scheduled, NULL, |
456 | __func__); | |
457 | ||
458 | if (scheduled) { | |
459 | fprintf(stderr, | |
460 | "%s: Co-routine was already scheduled in '%s'\n", | |
461 | __func__, scheduled); | |
462 | abort(); | |
463 | } | |
464 | ||
f0f81002 SH |
465 | /* The coroutine might run and release the last ctx reference before we |
466 | * invoke qemu_bh_schedule(). Take a reference to keep ctx alive until | |
467 | * we're done. | |
468 | */ | |
469 | aio_context_ref(ctx); | |
470 | ||
0c330a73 PB |
471 | QSLIST_INSERT_HEAD_ATOMIC(&ctx->scheduled_coroutines, |
472 | co, co_scheduled_next); | |
473 | qemu_bh_schedule(ctx->co_schedule_bh); | |
f0f81002 SH |
474 | |
475 | aio_context_unref(ctx); | |
0c330a73 PB |
476 | } |
477 | ||
478 | void aio_co_wake(struct Coroutine *co) | |
479 | { | |
480 | AioContext *ctx; | |
481 | ||
482 | /* Read coroutine before co->ctx. Matches smp_wmb in | |
483 | * qemu_coroutine_enter. | |
484 | */ | |
485 | smp_read_barrier_depends(); | |
486 | ctx = atomic_read(&co->ctx); | |
487 | ||
8865852e FZ |
488 | aio_co_enter(ctx, co); |
489 | } | |
490 | ||
491 | void aio_co_enter(AioContext *ctx, struct Coroutine *co) | |
492 | { | |
0c330a73 PB |
493 | if (ctx != qemu_get_current_aio_context()) { |
494 | aio_co_schedule(ctx, co); | |
495 | return; | |
496 | } | |
497 | ||
498 | if (qemu_in_coroutine()) { | |
499 | Coroutine *self = qemu_coroutine_self(); | |
500 | assert(self != co); | |
501 | QSIMPLEQ_INSERT_TAIL(&self->co_queue_wakeup, co, co_queue_next); | |
502 | } else { | |
503 | aio_context_acquire(ctx); | |
8865852e | 504 | qemu_aio_coroutine_enter(ctx, co); |
0c330a73 PB |
505 | aio_context_release(ctx); |
506 | } | |
507 | } | |
508 | ||
e3713e00 PB |
509 | void aio_context_ref(AioContext *ctx) |
510 | { | |
511 | g_source_ref(&ctx->source); | |
512 | } | |
513 | ||
514 | void aio_context_unref(AioContext *ctx) | |
515 | { | |
516 | g_source_unref(&ctx->source); | |
f627aab1 | 517 | } |
98563fc3 SH |
518 | |
519 | void aio_context_acquire(AioContext *ctx) | |
520 | { | |
3fe71223 | 521 | qemu_rec_mutex_lock(&ctx->lock); |
98563fc3 SH |
522 | } |
523 | ||
524 | void aio_context_release(AioContext *ctx) | |
525 | { | |
3fe71223 | 526 | qemu_rec_mutex_unlock(&ctx->lock); |
98563fc3 | 527 | } |