1
0
Fork 0

take the promise's future whilst still holding the metadata mutex

This commit is contained in:
Kevin Matz 2023-04-06 10:11:33 -04:00
parent b92f159d02
commit 388beecf8d
1 changed files with 13 additions and 9 deletions

View File

@ -403,15 +403,17 @@ void Widget::rebootBootloader()
*/
bool Widget::getSerialNumber(int timeout)
{
auto msg = std::make_shared<Pro::MsgGetWidgetSerialRequest>();
std::future<bool> ftr;
{
std::scoped_lock lock(mtx_metadata_);
reply_serialNumber_ = std::promise<bool>(); // expect a reply to this message
reply_serialNumber_ = std::promise<bool>(); // expect a reply to this message
ftr = reply_serialNumber_.get_future();
}
auto ftr = reply_serialNumber_.get_future(); // will be "true" when reply received
auto msg = std::make_shared<Pro::MsgGetWidgetSerialRequest>();
sendMessage(msg);
auto status = ftr.wait_for(std::chrono::milliseconds(timeout)); // wait for the reply
switch (status) {
switch (ftr.wait_for(std::chrono::milliseconds(timeout))) {
case std::future_status::ready:
return true;
case std::future_status::timeout:
@ -430,16 +432,18 @@ bool Widget::getSerialNumber(int timeout)
*/
bool Widget::getParameters(size_t user_length, int timeout)
{
auto msg = std::make_shared<Pro::MsgGetWidgetParametersRequest>();
std::future<bool> ftr;
{
std::scoped_lock lock(mtx_metadata_);
reply_parameters_ = std::promise<bool>(); // expect a reply to this message
ftr = reply_parameters_.get_future();
}
auto ftr = reply_parameters_.get_future(); // will be "true" when reply received
auto msg = std::make_shared<Pro::MsgGetWidgetParametersRequest>();
msg->size = std::min(user_length, Pro::USER_CONFIGURATION_MAX);
sendMessage(msg);
auto status = ftr.wait_for(std::chrono::milliseconds(timeout)); // wait for the reply
switch (status) {
switch (ftr.wait_for(std::chrono::milliseconds(timeout))) {
case std::future_status::ready:
return true;
case std::future_status::timeout: