aio-wait.h (17e1e49814096a3daaa8e5a73acd56a0f30bdc18) | aio-wait.h (d73415a315471ac0b127ed3fad45c8ec5d711de1) |
---|---|
1/* 2 * AioContext wait support 3 * 4 * Copyright (C) 2018 Red Hat, Inc. 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 --- 66 unchanged lines hidden (view full) --- 75 * wait on conditions between two IOThreads since that could lead to deadlock, 76 * go via the main loop instead. 77 */ 78#define AIO_WAIT_WHILE(ctx, cond) ({ \ 79 bool waited_ = false; \ 80 AioWait *wait_ = &global_aio_wait; \ 81 AioContext *ctx_ = (ctx); \ 82 /* Increment wait_->num_waiters before evaluating cond. */ \ | 1/* 2 * AioContext wait support 3 * 4 * Copyright (C) 2018 Red Hat, Inc. 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 --- 66 unchanged lines hidden (view full) --- 75 * wait on conditions between two IOThreads since that could lead to deadlock, 76 * go via the main loop instead. 77 */ 78#define AIO_WAIT_WHILE(ctx, cond) ({ \ 79 bool waited_ = false; \ 80 AioWait *wait_ = &global_aio_wait; \ 81 AioContext *ctx_ = (ctx); \ 82 /* Increment wait_->num_waiters before evaluating cond. */ \ |
83 atomic_inc(&wait_->num_waiters); \ | 83 qatomic_inc(&wait_->num_waiters); \ |
84 if (ctx_ && in_aio_context_home_thread(ctx_)) { \ 85 while ((cond)) { \ 86 aio_poll(ctx_, true); \ 87 waited_ = true; \ 88 } \ 89 } else { \ 90 assert(qemu_get_current_aio_context() == \ 91 qemu_get_aio_context()); \ 92 while ((cond)) { \ 93 if (ctx_) { \ 94 aio_context_release(ctx_); \ 95 } \ 96 aio_poll(qemu_get_aio_context(), true); \ 97 if (ctx_) { \ 98 aio_context_acquire(ctx_); \ 99 } \ 100 waited_ = true; \ 101 } \ 102 } \ | 84 if (ctx_ && in_aio_context_home_thread(ctx_)) { \ 85 while ((cond)) { \ 86 aio_poll(ctx_, true); \ 87 waited_ = true; \ 88 } \ 89 } else { \ 90 assert(qemu_get_current_aio_context() == \ 91 qemu_get_aio_context()); \ 92 while ((cond)) { \ 93 if (ctx_) { \ 94 aio_context_release(ctx_); \ 95 } \ 96 aio_poll(qemu_get_aio_context(), true); \ 97 if (ctx_) { \ 98 aio_context_acquire(ctx_); \ 99 } \ 100 waited_ = true; \ 101 } \ 102 } \ |
103 atomic_dec(&wait_->num_waiters); \ | 103 qatomic_dec(&wait_->num_waiters); \ |
104 waited_; }) 105 106/** 107 * aio_wait_kick: 108 * Wake up the main thread if it is waiting on AIO_WAIT_WHILE(). During 109 * synchronous operations performed in an IOThread, the main thread lets the 110 * IOThread's event loop run, waiting for the operation to complete. A 111 * aio_wait_kick() call will wake up the main thread. --- 38 unchanged lines hidden --- | 104 waited_; }) 105 106/** 107 * aio_wait_kick: 108 * Wake up the main thread if it is waiting on AIO_WAIT_WHILE(). During 109 * synchronous operations performed in an IOThread, the main thread lets the 110 * IOThread's event loop run, waiting for the operation to complete. A 111 * aio_wait_kick() call will wake up the main thread. --- 38 unchanged lines hidden --- |