Avoid returning objects with a reference parameter
This commit is contained in:
parent
24b030d6bd
commit
f11fef9ee5
@ -428,9 +428,9 @@ enum class MsgType {
|
|||||||
CloseDevice,
|
CloseDevice,
|
||||||
EnumeratePlayback,
|
EnumeratePlayback,
|
||||||
EnumerateCapture,
|
EnumerateCapture,
|
||||||
QuitThread,
|
|
||||||
|
|
||||||
Count
|
Count,
|
||||||
|
QuitThread = Count
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr char MessageStr[static_cast<size_t>(MsgType::Count)][20]{
|
constexpr char MessageStr[static_cast<size_t>(MsgType::Count)][20]{
|
||||||
@ -441,8 +441,7 @@ constexpr char MessageStr[static_cast<size_t>(MsgType::Count)][20]{
|
|||||||
"Stop Device",
|
"Stop Device",
|
||||||
"Close Device",
|
"Close Device",
|
||||||
"Enumerate Playback",
|
"Enumerate Playback",
|
||||||
"Enumerate Capture",
|
"Enumerate Capture"
|
||||||
"Quit"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -462,6 +461,8 @@ struct WasapiProxy {
|
|||||||
WasapiProxy *mProxy;
|
WasapiProxy *mProxy;
|
||||||
const char *mParam;
|
const char *mParam;
|
||||||
std::promise<HRESULT> mPromise;
|
std::promise<HRESULT> mPromise;
|
||||||
|
|
||||||
|
operator bool() const noexcept { return mType != MsgType::QuitThread; }
|
||||||
};
|
};
|
||||||
static std::deque<Msg> mMsgQueue;
|
static std::deque<Msg> mMsgQueue;
|
||||||
static std::mutex mMsgQueueLock;
|
static std::mutex mMsgQueueLock;
|
||||||
@ -491,13 +492,13 @@ struct WasapiProxy {
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool popMessage(Msg &msg)
|
static Msg popMessage()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock{mMsgQueueLock};
|
std::unique_lock<std::mutex> lock{mMsgQueueLock};
|
||||||
mMsgQueueCond.wait(lock, []{return !mMsgQueue.empty();});
|
mMsgQueueCond.wait(lock, []{return !mMsgQueue.empty();});
|
||||||
msg = std::move(mMsgQueue.front());
|
Msg msg{std::move(mMsgQueue.front())};
|
||||||
mMsgQueue.pop_front();
|
mMsgQueue.pop_front();
|
||||||
return msg.mType != MsgType::QuitThread;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int messageHandler(std::promise<HRESULT> *promise);
|
static int messageHandler(std::promise<HRESULT> *promise);
|
||||||
@ -537,8 +538,7 @@ int WasapiProxy::messageHandler(std::promise<HRESULT> *promise)
|
|||||||
|
|
||||||
TRACE("Starting message loop\n");
|
TRACE("Starting message loop\n");
|
||||||
uint deviceCount{0};
|
uint deviceCount{0};
|
||||||
Msg msg;
|
while(Msg msg{popMessage()})
|
||||||
while(popMessage(msg))
|
|
||||||
{
|
{
|
||||||
TRACE("Got message \"%s\" (0x%04x, this=%p, param=%p)\n",
|
TRACE("Got message \"%s\" (0x%04x, this=%p, param=%p)\n",
|
||||||
MessageStr[static_cast<size_t>(msg.mType)], static_cast<uint>(msg.mType),
|
MessageStr[static_cast<size_t>(msg.mType)], static_cast<uint>(msg.mType),
|
||||||
@ -614,11 +614,11 @@ int WasapiProxy::messageHandler(std::promise<HRESULT> *promise)
|
|||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
default:
|
case MsgType::QuitThread:
|
||||||
ERR("Unexpected message: %u\n", static_cast<uint>(msg.mType));
|
break;
|
||||||
msg.mPromise.set_value(E_FAIL);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
ERR("Unexpected message: %u\n", static_cast<uint>(msg.mType));
|
||||||
|
msg.mPromise.set_value(E_FAIL);
|
||||||
}
|
}
|
||||||
TRACE("Message loop finished\n");
|
TRACE("Message loop finished\n");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user