blob: f30d011ebc0dc4601ee78ff22e03a7b7576e3cad [file] [log] [blame]
Kevin Wolf4f999d02009-10-22 17:54:37 +02001/*
2 * QEMU System Emulator
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
Peter Maydelld38ea872016-01-29 17:50:05 +000025#include "qemu/osdep.h"
Markus Armbrusterda34e652016-03-14 09:01:28 +010026#include "qapi/error.h"
Kevin Wolf4f999d02009-10-22 17:54:37 +020027#include "qemu-common.h"
Paolo Bonzini737e1502012-12-17 18:19:44 +010028#include "block/aio.h"
Stefan Hajnoczi9b342772013-03-07 13:41:47 +010029#include "block/thread-pool.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010030#include "qemu/main-loop.h"
Paolo Bonzini0ceb8492014-07-07 15:18:04 +020031#include "qemu/atomic.h"
Paolo Bonzini0187f5c2016-07-04 18:33:20 +020032#include "block/raw-aio.h"
Kevin Wolf9a1e9482009-10-22 17:54:38 +020033
Kevin Wolf4f999d02009-10-22 17:54:37 +020034/***********************************************************/
35/* bottom halves (can be seen as timers which expire ASAP) */
36
37struct QEMUBH {
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +020038 AioContext *ctx;
Kevin Wolf4f999d02009-10-22 17:54:37 +020039 QEMUBHFunc *cb;
40 void *opaque;
Kevin Wolf4f999d02009-10-22 17:54:37 +020041 QEMUBH *next;
Stefan Weil9b47b172012-04-29 19:08:45 +020042 bool scheduled;
43 bool idle;
44 bool deleted;
Kevin Wolf4f999d02009-10-22 17:54:37 +020045};
46
Paolo Bonzini5b8bb352016-10-03 18:14:15 +020047void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
48{
49 QEMUBH *bh;
50 bh = g_new(QEMUBH, 1);
51 *bh = (QEMUBH){
52 .ctx = ctx,
53 .cb = cb,
54 .opaque = opaque,
55 };
56 qemu_mutex_lock(&ctx->bh_lock);
57 bh->next = ctx->first_bh;
58 bh->scheduled = 1;
59 bh->deleted = 1;
60 /* Make sure that the members are ready before putting bh into list */
61 smp_wmb();
62 ctx->first_bh = bh;
63 qemu_mutex_unlock(&ctx->bh_lock);
64}
65
Paolo Bonzinif627aab2012-10-29 23:45:23 +010066QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
Kevin Wolf4f999d02009-10-22 17:54:37 +020067{
68 QEMUBH *bh;
Paolo Bonziniee823102014-12-17 16:10:00 +010069 bh = g_new(QEMUBH, 1);
70 *bh = (QEMUBH){
71 .ctx = ctx,
72 .cb = cb,
73 .opaque = opaque,
74 };
Liu Ping Fandcc772e2013-07-16 12:28:58 +080075 qemu_mutex_lock(&ctx->bh_lock);
Paolo Bonzinif627aab2012-10-29 23:45:23 +010076 bh->next = ctx->first_bh;
Liu Ping Fandcc772e2013-07-16 12:28:58 +080077 /* Make sure that the members are ready before putting bh into list */
78 smp_wmb();
Paolo Bonzinif627aab2012-10-29 23:45:23 +010079 ctx->first_bh = bh;
Liu Ping Fandcc772e2013-07-16 12:28:58 +080080 qemu_mutex_unlock(&ctx->bh_lock);
Kevin Wolf4f999d02009-10-22 17:54:37 +020081 return bh;
82}
83
Pavel Dovgalyukdf281b82015-09-17 19:24:50 +030084void aio_bh_call(QEMUBH *bh)
85{
86 bh->cb(bh->opaque);
87}
88
Liu Ping Fandcc772e2013-07-16 12:28:58 +080089/* Multiple occurrences of aio_bh_poll cannot be called concurrently */
Paolo Bonzinif627aab2012-10-29 23:45:23 +010090int aio_bh_poll(AioContext *ctx)
Kevin Wolf4f999d02009-10-22 17:54:37 +020091{
Kevin Wolf7887f622011-06-07 17:51:21 +020092 QEMUBH *bh, **bhp, *next;
Kevin Wolf4f999d02009-10-22 17:54:37 +020093 int ret;
Kevin Wolf648fb0e2011-09-01 16:16:10 +020094
Paolo Bonzinif627aab2012-10-29 23:45:23 +010095 ctx->walking_bh++;
Kevin Wolf4f999d02009-10-22 17:54:37 +020096
97 ret = 0;
Paolo Bonzinif627aab2012-10-29 23:45:23 +010098 for (bh = ctx->first_bh; bh; bh = next) {
Liu Ping Fandcc772e2013-07-16 12:28:58 +080099 /* Make sure that fetching bh happens before accessing its members */
100 smp_read_barrier_depends();
Kevin Wolf7887f622011-06-07 17:51:21 +0200101 next = bh->next;
Paolo Bonzinie8d3b1a2015-04-07 17:16:19 +0200102 /* The atomic_xchg is paired with the one in qemu_bh_schedule. The
103 * implicit memory barrier ensures that the callback sees all writes
104 * done by the scheduling thread. It also ensures that the scheduling
105 * thread sees the zero before bh->cb has run, and thus will call
106 * aio_notify again if necessary.
107 */
Paolo Bonzini5b8bb352016-10-03 18:14:15 +0200108 if (atomic_xchg(&bh->scheduled, 0)) {
Stefan Hajnoczica96ac42015-07-28 18:34:09 +0200109 /* Idle BHs and the notify BH don't count as progress */
110 if (!bh->idle && bh != ctx->notify_dummy_bh) {
Kevin Wolf4f999d02009-10-22 17:54:37 +0200111 ret = 1;
Stefan Hajnoczica96ac42015-07-28 18:34:09 +0200112 }
Kevin Wolf4f999d02009-10-22 17:54:37 +0200113 bh->idle = 0;
Pavel Dovgalyukdf281b82015-09-17 19:24:50 +0300114 aio_bh_call(bh);
Kevin Wolf4f999d02009-10-22 17:54:37 +0200115 }
116 }
117
Paolo Bonzinif627aab2012-10-29 23:45:23 +0100118 ctx->walking_bh--;
Kevin Wolf648fb0e2011-09-01 16:16:10 +0200119
Kevin Wolf4f999d02009-10-22 17:54:37 +0200120 /* remove deleted bhs */
Paolo Bonzinif627aab2012-10-29 23:45:23 +0100121 if (!ctx->walking_bh) {
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800122 qemu_mutex_lock(&ctx->bh_lock);
Paolo Bonzinif627aab2012-10-29 23:45:23 +0100123 bhp = &ctx->first_bh;
Kevin Wolf648fb0e2011-09-01 16:16:10 +0200124 while (*bhp) {
125 bh = *bhp;
Paolo Bonzini5b8bb352016-10-03 18:14:15 +0200126 if (bh->deleted && !bh->scheduled) {
Kevin Wolf648fb0e2011-09-01 16:16:10 +0200127 *bhp = bh->next;
128 g_free(bh);
129 } else {
130 bhp = &bh->next;
131 }
132 }
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800133 qemu_mutex_unlock(&ctx->bh_lock);
Kevin Wolf4f999d02009-10-22 17:54:37 +0200134 }
135
136 return ret;
137}
138
139void qemu_bh_schedule_idle(QEMUBH *bh)
140{
Kevin Wolf4f999d02009-10-22 17:54:37 +0200141 bh->idle = 1;
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800142 /* Make sure that idle & any writes needed by the callback are done
143 * before the locations are read in the aio_bh_poll.
144 */
Paolo Bonzinie8d3b1a2015-04-07 17:16:19 +0200145 atomic_mb_set(&bh->scheduled, 1);
Kevin Wolf4f999d02009-10-22 17:54:37 +0200146}
147
148void qemu_bh_schedule(QEMUBH *bh)
149{
Stefan Hajnoczi924fe122014-06-03 11:21:01 +0200150 AioContext *ctx;
151
Stefan Hajnoczi924fe122014-06-03 11:21:01 +0200152 ctx = bh->ctx;
Kevin Wolf4f999d02009-10-22 17:54:37 +0200153 bh->idle = 0;
Paolo Bonzinie8d3b1a2015-04-07 17:16:19 +0200154 /* The memory barrier implicit in atomic_xchg makes sure that:
Stefan Hajnoczi924fe122014-06-03 11:21:01 +0200155 * 1. idle & any writes needed by the callback are done before the
156 * locations are read in the aio_bh_poll.
157 * 2. ctx is loaded before scheduled is set and the callback has a chance
158 * to execute.
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800159 */
Paolo Bonzinie8d3b1a2015-04-07 17:16:19 +0200160 if (atomic_xchg(&bh->scheduled, 1) == 0) {
161 aio_notify(ctx);
162 }
Kevin Wolf4f999d02009-10-22 17:54:37 +0200163}
164
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800165
166/* This func is async.
167 */
Kevin Wolf4f999d02009-10-22 17:54:37 +0200168void qemu_bh_cancel(QEMUBH *bh)
169{
170 bh->scheduled = 0;
171}
172
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800173/* This func is async.The bottom half will do the delete action at the finial
174 * end.
175 */
Kevin Wolf4f999d02009-10-22 17:54:37 +0200176void qemu_bh_delete(QEMUBH *bh)
177{
178 bh->scheduled = 0;
179 bh->deleted = 1;
180}
181
Paolo Bonzini845ca102014-07-09 11:53:01 +0200182int64_t
183aio_compute_timeout(AioContext *ctx)
Kevin Wolf4f999d02009-10-22 17:54:37 +0200184{
Paolo Bonzini845ca102014-07-09 11:53:01 +0200185 int64_t deadline;
186 int timeout = -1;
Kevin Wolf4f999d02009-10-22 17:54:37 +0200187 QEMUBH *bh;
188
Paolo Bonzinif627aab2012-10-29 23:45:23 +0100189 for (bh = ctx->first_bh; bh; bh = bh->next) {
Paolo Bonzini5b8bb352016-10-03 18:14:15 +0200190 if (bh->scheduled) {
Kevin Wolf4f999d02009-10-22 17:54:37 +0200191 if (bh->idle) {
192 /* idle bottom halves will be polled at least
193 * every 10ms */
Paolo Bonzini845ca102014-07-09 11:53:01 +0200194 timeout = 10000000;
Kevin Wolf4f999d02009-10-22 17:54:37 +0200195 } else {
196 /* non-idle bottom halves will be executed
197 * immediately */
Paolo Bonzini845ca102014-07-09 11:53:01 +0200198 return 0;
Kevin Wolf4f999d02009-10-22 17:54:37 +0200199 }
200 }
201 }
Kevin Wolf4f999d02009-10-22 17:54:37 +0200202
Paolo Bonzini845ca102014-07-09 11:53:01 +0200203 deadline = timerlistgroup_deadline_ns(&ctx->tlg);
Alex Bligh533a8cf2013-08-21 16:02:51 +0100204 if (deadline == 0) {
Paolo Bonzini845ca102014-07-09 11:53:01 +0200205 return 0;
Alex Bligh533a8cf2013-08-21 16:02:51 +0100206 } else {
Paolo Bonzini845ca102014-07-09 11:53:01 +0200207 return qemu_soonest_timeout(timeout, deadline);
Alex Bligh533a8cf2013-08-21 16:02:51 +0100208 }
Paolo Bonzini845ca102014-07-09 11:53:01 +0200209}
Alex Bligh533a8cf2013-08-21 16:02:51 +0100210
Paolo Bonzini845ca102014-07-09 11:53:01 +0200211static gboolean
212aio_ctx_prepare(GSource *source, gint *timeout)
213{
214 AioContext *ctx = (AioContext *) source;
215
Paolo Bonzinieabc9772015-07-21 16:07:51 +0200216 atomic_or(&ctx->notify_me, 1);
217
Paolo Bonzini845ca102014-07-09 11:53:01 +0200218 /* We assume there is no timeout already supplied */
219 *timeout = qemu_timeout_ns_to_ms(aio_compute_timeout(ctx));
Paolo Bonzinia3462c62014-07-09 11:53:08 +0200220
221 if (aio_prepare(ctx)) {
222 *timeout = 0;
223 }
224
Paolo Bonzini845ca102014-07-09 11:53:01 +0200225 return *timeout == 0;
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200226}
227
228static gboolean
229aio_ctx_check(GSource *source)
230{
231 AioContext *ctx = (AioContext *) source;
232 QEMUBH *bh;
233
Paolo Bonzinieabc9772015-07-21 16:07:51 +0200234 atomic_and(&ctx->notify_me, ~1);
Paolo Bonzini05e514b2015-07-21 16:07:53 +0200235 aio_notify_accept(ctx);
Paolo Bonzini21a03d12015-07-21 16:07:52 +0200236
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200237 for (bh = ctx->first_bh; bh; bh = bh->next) {
Paolo Bonzini5b8bb352016-10-03 18:14:15 +0200238 if (bh->scheduled) {
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200239 return true;
Cao jin6977d902016-07-14 21:10:43 +0800240 }
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200241 }
Alex Bligh533a8cf2013-08-21 16:02:51 +0100242 return aio_pending(ctx) || (timerlistgroup_deadline_ns(&ctx->tlg) == 0);
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200243}
244
245static gboolean
246aio_ctx_dispatch(GSource *source,
247 GSourceFunc callback,
248 gpointer user_data)
249{
250 AioContext *ctx = (AioContext *) source;
251
252 assert(callback == NULL);
Paolo Bonzinie4c7e2d2014-07-09 11:53:05 +0200253 aio_dispatch(ctx);
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200254 return true;
255}
256
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200257static void
258aio_ctx_finalize(GSource *source)
259{
260 AioContext *ctx = (AioContext *) source;
261
Stefan Hajnoczica96ac42015-07-28 18:34:09 +0200262 qemu_bh_delete(ctx->notify_dummy_bh);
Stefan Hajnoczi9b342772013-03-07 13:41:47 +0100263 thread_pool_free(ctx->thread_pool);
Stefan Hajnoczia0769722015-07-28 18:34:08 +0200264
Paolo Bonzini0187f5c2016-07-04 18:33:20 +0200265#ifdef CONFIG_LINUX_AIO
266 if (ctx->linux_aio) {
267 laio_detach_aio_context(ctx->linux_aio, ctx);
268 laio_cleanup(ctx->linux_aio);
269 ctx->linux_aio = NULL;
270 }
271#endif
272
Stefan Hajnoczia0769722015-07-28 18:34:08 +0200273 qemu_mutex_lock(&ctx->bh_lock);
274 while (ctx->first_bh) {
275 QEMUBH *next = ctx->first_bh->next;
276
277 /* qemu_bh_delete() must have been called on BHs in this AioContext */
278 assert(ctx->first_bh->deleted);
279
280 g_free(ctx->first_bh);
281 ctx->first_bh = next;
282 }
283 qemu_mutex_unlock(&ctx->bh_lock);
284
Fam Zhengdca21ef2015-10-23 11:08:05 +0800285 aio_set_event_notifier(ctx, &ctx->notifier, false, NULL);
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200286 event_notifier_cleanup(&ctx->notifier);
Stefan Hajnoczi98563fc2014-03-03 11:30:04 +0100287 rfifolock_destroy(&ctx->lock);
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800288 qemu_mutex_destroy(&ctx->bh_lock);
Alex Blighdae21b92013-08-21 16:02:49 +0100289 timerlistgroup_deinit(&ctx->tlg);
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200290}
291
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200292static GSourceFuncs aio_source_funcs = {
293 aio_ctx_prepare,
294 aio_ctx_check,
295 aio_ctx_dispatch,
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200296 aio_ctx_finalize
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200297};
298
299GSource *aio_get_g_source(AioContext *ctx)
300{
301 g_source_ref(&ctx->source);
302 return &ctx->source;
303}
Paolo Bonzinia915f4b2012-09-13 12:28:51 +0200304
Stefan Hajnoczi9b342772013-03-07 13:41:47 +0100305ThreadPool *aio_get_thread_pool(AioContext *ctx)
306{
307 if (!ctx->thread_pool) {
308 ctx->thread_pool = thread_pool_new(ctx);
309 }
310 return ctx->thread_pool;
311}
312
Paolo Bonzini0187f5c2016-07-04 18:33:20 +0200313#ifdef CONFIG_LINUX_AIO
314LinuxAioState *aio_get_linux_aio(AioContext *ctx)
315{
316 if (!ctx->linux_aio) {
317 ctx->linux_aio = laio_init();
318 laio_attach_aio_context(ctx->linux_aio, ctx);
319 }
320 return ctx->linux_aio;
321}
322#endif
323
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200324void aio_notify(AioContext *ctx)
325{
Paolo Bonzinieabc9772015-07-21 16:07:51 +0200326 /* Write e.g. bh->scheduled before reading ctx->notify_me. Pairs
327 * with atomic_or in aio_ctx_prepare or atomic_add in aio_poll.
328 */
Paolo Bonzini0ceb8492014-07-07 15:18:04 +0200329 smp_mb();
Paolo Bonzinieabc9772015-07-21 16:07:51 +0200330 if (ctx->notify_me) {
Paolo Bonzini0ceb8492014-07-07 15:18:04 +0200331 event_notifier_set(&ctx->notifier);
Paolo Bonzini05e514b2015-07-21 16:07:53 +0200332 atomic_mb_set(&ctx->notified, true);
333 }
334}
335
336void aio_notify_accept(AioContext *ctx)
337{
338 if (atomic_xchg(&ctx->notified, false)) {
339 event_notifier_test_and_clear(&ctx->notifier);
Paolo Bonzini0ceb8492014-07-07 15:18:04 +0200340 }
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200341}
342
Alex Blighd5541d82013-08-21 16:02:50 +0100343static void aio_timerlist_notify(void *opaque)
344{
345 aio_notify(opaque);
346}
347
Stefan Hajnoczida5e1de2015-06-03 10:15:33 +0100348static void aio_rfifolock_cb(void *opaque)
349{
Stefan Hajnoczica96ac42015-07-28 18:34:09 +0200350 AioContext *ctx = opaque;
351
Stefan Hajnoczida5e1de2015-06-03 10:15:33 +0100352 /* Kick owner thread in case they are blocked in aio_poll() */
Stefan Hajnoczica96ac42015-07-28 18:34:09 +0200353 qemu_bh_schedule(ctx->notify_dummy_bh);
354}
355
356static void notify_dummy_bh(void *opaque)
357{
358 /* Do nothing, we were invoked just to force the event loop to iterate */
Stefan Hajnoczida5e1de2015-06-03 10:15:33 +0100359}
360
Paolo Bonzini21a03d12015-07-21 16:07:52 +0200361static void event_notifier_dummy_cb(EventNotifier *e)
362{
363}
364
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300365AioContext *aio_context_new(Error **errp)
Paolo Bonzinif627aab2012-10-29 23:45:23 +0100366{
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300367 int ret;
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200368 AioContext *ctx;
Fam Zheng37fcee52015-10-30 12:06:28 +0800369
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200370 ctx = (AioContext *) g_source_new(&aio_source_funcs, sizeof(AioContext));
Cao jin7e003462016-07-15 18:28:44 +0800371 aio_context_setup(ctx);
372
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300373 ret = event_notifier_init(&ctx->notifier, false);
374 if (ret < 0) {
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300375 error_setg_errno(errp, -ret, "Failed to initialize event notifier");
Fam Zheng37fcee52015-10-30 12:06:28 +0800376 goto fail;
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300377 }
Paolo Bonzinifcf5def2014-12-17 16:09:58 +0100378 g_source_set_can_recurse(&ctx->source, true);
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300379 aio_set_event_notifier(ctx, &ctx->notifier,
Fam Zhengdca21ef2015-10-23 11:08:05 +0800380 false,
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300381 (EventNotifierHandler *)
Paolo Bonzini21a03d12015-07-21 16:07:52 +0200382 event_notifier_dummy_cb);
Paolo Bonzini0187f5c2016-07-04 18:33:20 +0200383#ifdef CONFIG_LINUX_AIO
384 ctx->linux_aio = NULL;
385#endif
Stefan Hajnoczi9b342772013-03-07 13:41:47 +0100386 ctx->thread_pool = NULL;
Liu Ping Fandcc772e2013-07-16 12:28:58 +0800387 qemu_mutex_init(&ctx->bh_lock);
Stefan Hajnoczida5e1de2015-06-03 10:15:33 +0100388 rfifolock_init(&ctx->lock, aio_rfifolock_cb, ctx);
Alex Blighd5541d82013-08-21 16:02:50 +0100389 timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx);
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200390
Stefan Hajnoczica96ac42015-07-28 18:34:09 +0200391 ctx->notify_dummy_bh = aio_bh_new(ctx, notify_dummy_bh, NULL);
392
Paolo Bonzini2f4dc3c2012-09-24 18:44:14 +0200393 return ctx;
Fam Zheng37fcee52015-10-30 12:06:28 +0800394fail:
395 g_source_destroy(&ctx->source);
396 return NULL;
Paolo Bonzinie3713e02012-09-24 14:57:41 +0200397}
398
399void aio_context_ref(AioContext *ctx)
400{
401 g_source_ref(&ctx->source);
402}
403
404void aio_context_unref(AioContext *ctx)
405{
406 g_source_unref(&ctx->source);
Paolo Bonzinif627aab2012-10-29 23:45:23 +0100407}
Stefan Hajnoczi98563fc2014-03-03 11:30:04 +0100408
409void aio_context_acquire(AioContext *ctx)
410{
411 rfifolock_lock(&ctx->lock);
412}
413
414void aio_context_release(AioContext *ctx)
415{
416 rfifolock_unlock(&ctx->lock);
417}