From f11fef9ee549ddf0ea14ee76dd64ad25d16babd6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 16 Mar 2021 22:38:32 -0700 Subject: Avoid returning objects with a reference parameter --- alc/backends/wasapi.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'alc/backends') diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index b5283e2a..4f9709e4 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -428,9 +428,9 @@ enum class MsgType { CloseDevice, EnumeratePlayback, EnumerateCapture, - QuitThread, - Count + Count, + QuitThread = Count }; constexpr char MessageStr[static_cast(MsgType::Count)][20]{ @@ -441,8 +441,7 @@ constexpr char MessageStr[static_cast(MsgType::Count)][20]{ "Stop Device", "Close Device", "Enumerate Playback", - "Enumerate Capture", - "Quit" + "Enumerate Capture" }; @@ -462,6 +461,8 @@ struct WasapiProxy { WasapiProxy *mProxy; const char *mParam; std::promise mPromise; + + operator bool() const noexcept { return mType != MsgType::QuitThread; } }; static std::deque mMsgQueue; static std::mutex mMsgQueueLock; @@ -491,13 +492,13 @@ struct WasapiProxy { return future; } - static bool popMessage(Msg &msg) + static Msg popMessage() { std::unique_lock lock{mMsgQueueLock}; mMsgQueueCond.wait(lock, []{return !mMsgQueue.empty();}); - msg = std::move(mMsgQueue.front()); + Msg msg{std::move(mMsgQueue.front())}; mMsgQueue.pop_front(); - return msg.mType != MsgType::QuitThread; + return msg; } static int messageHandler(std::promise *promise); @@ -537,8 +538,7 @@ int WasapiProxy::messageHandler(std::promise *promise) TRACE("Starting message loop\n"); uint deviceCount{0}; - Msg msg; - while(popMessage(msg)) + while(Msg msg{popMessage()}) { TRACE("Got message \"%s\" (0x%04x, this=%p, param=%p)\n", MessageStr[static_cast(msg.mType)], static_cast(msg.mType), @@ -614,11 +614,11 @@ int WasapiProxy::messageHandler(std::promise *promise) CoUninitialize(); continue; - default: - ERR("Unexpected message: %u\n", static_cast(msg.mType)); - msg.mPromise.set_value(E_FAIL); - continue; + case MsgType::QuitThread: + break; } + ERR("Unexpected message: %u\n", static_cast(msg.mType)); + msg.mPromise.set_value(E_FAIL); } TRACE("Message loop finished\n"); -- cgit v1.2.3