diff options
author | Roman Kiryanov <rkir@google.com> | 2024-02-02 13:42:39 -0800 |
---|---|---|
committer | Roman Kiryanov <rkir@google.com> | 2024-02-13 15:15:18 -0800 |
commit | a1aa8bc1b94ca027d3137c2381aec6e12ef38c61 (patch) | |
tree | 41cdfca30dfba6a24b3d783ded12fcc87bfebb7d | |
parent | e54080729377e8481cf3d79f5954398a276571e4 (diff) | |
download | qemu-a1aa8bc1b94ca027d3137c2381aec6e12ef38c61.tar.gz |
Call qemu_bh_schedule after mutations
to avoid missing the mutation events in
aio_notify (which is called inside).
Bug: 323522098
Test: CtsMediaDecoderTestCases
Change-Id: I55bb34c22b70a862f6e4b992a6ae533e0eb9f929
Signed-off-by: Roman Kiryanov <rkir@google.com>
-rw-r--r-- | android-qemu2-glue/base/async/Looper.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/android-qemu2-glue/base/async/Looper.cpp b/android-qemu2-glue/base/async/Looper.cpp index f51522816a..0ea0a814ad 100644 --- a/android-qemu2-glue/base/async/Looper.cpp +++ b/android-qemu2-glue/base/async/Looper.cpp @@ -29,6 +29,7 @@ extern "C" { #include "chardev/char.h" } // extern "C" +#include <memory> #include <string_view> #include <unordered_set> #include <utility> @@ -70,12 +71,9 @@ typedef ::android::base::Looper::FdWatch BaseFdWatch; // class QemuLooper : public BaseLooper { public: - QemuLooper() = default; + QemuLooper() : mQemuBh(qemu_bh_new(handleBottomHalf, this)) {} virtual ~QemuLooper() { - if (mQemuBh) { - qemu_bh_delete(mQemuBh); - } DCHECK(mPendingFdWatches.empty()); } @@ -349,6 +347,12 @@ public: private: typedef std::unordered_set<FdWatch*> FdWatchSet; + struct QEMUBHDeleter { + void operator()(QEMUBH* x) const { + qemu_bh_delete(x); + } + }; + static inline QemuLooper* asQemuLooper(BaseLooper* looper) { return reinterpret_cast<QemuLooper*>(looper); } @@ -357,16 +361,11 @@ private: DCHECK(watch); DCHECK(!watch->isPending()); - if (mPendingFdWatches.empty()) { - // Ensure the bottom-half is triggered to act on pending - // watches as soon as possible. - if (!mQemuBh) { - mQemuBh = qemu_bh_new(handleBottomHalf, this); - } - qemu_bh_schedule(mQemuBh); - } - + const bool firstFdWatch = mPendingFdWatches.empty(); CHECK(mPendingFdWatches.insert(watch).second) << "duplicate FdWatch"; + if (firstFdWatch) { + qemu_bh_schedule(mQemuBh.get()); + } } void delPendingFdWatch(FdWatch* watch) { @@ -389,7 +388,7 @@ private: } } - QEMUBH* mQemuBh = nullptr; + const std::unique_ptr<QEMUBH, QEMUBHDeleter> mQemuBh; FdWatchSet mPendingFdWatches; }; |