Device: Disk lock the script/wivi commands

add-device-sharing
Emily Brooks 2022-11-09 19:28:00 -05:00 committed by Kyle Schwarz
parent 96fe8895fc
commit c9d8a4f0a9
1 changed files with 10 additions and 0 deletions

View File

@ -421,6 +421,8 @@ int8_t Device::prepareScriptLoad() {
static std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Network::NetID::CoreMiniPreLoad); static std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Network::NetID::CoreMiniPreLoad);
std::lock_guard<std::mutex> lg(diskLock);
if(!com->sendCommand(Command::CoreMiniPreload)) if(!com->sendCommand(Command::CoreMiniPreload))
return false; return false;
@ -448,6 +450,8 @@ bool Device::startScript()
return false; return false;
} }
std::lock_guard<std::mutex> lg(diskLock);
uint8_t LocationSdCard = 1; //Only support starting a coremini in an SDCard uint8_t LocationSdCard = 1; //Only support starting a coremini in an SDCard
auto generic = com->sendCommand(Command::LoadCoreMini, LocationSdCard); auto generic = com->sendCommand(Command::LoadCoreMini, LocationSdCard);
@ -467,6 +471,8 @@ bool Device::stopScript()
return false; return false;
} }
std::lock_guard<std::mutex> lg(diskLock);
auto generic = com->sendCommand(Command::ClearCoreMini); auto generic = com->sendCommand(Command::ClearCoreMini);
if(!generic) if(!generic)
@ -955,9 +961,11 @@ void Device::wiviThreadBody() {
} }
if(!clearMasks.empty()) { if(!clearMasks.empty()) {
dl.lock();
const auto clearMasksGenericResp = com->waitForMessageSync([this, &clearMasks]() { const auto clearMasksGenericResp = com->waitForMessageSync([this, &clearMasks]() {
return com->sendCommand(Command::WiVICommand, WiVI::CommandPacket::ClearUploads::Encode(clearMasks)); return com->sendCommand(Command::WiVICommand, WiVI::CommandPacket::ClearUploads::Encode(clearMasks));
}, filter); }, filter);
dl.unlock();
if(!clearMasksGenericResp if(!clearMasksGenericResp
|| clearMasksGenericResp->type != Message::Type::WiVICommandResponse || clearMasksGenericResp->type != Message::Type::WiVICommandResponse
@ -1098,6 +1106,7 @@ std::optional<bool> Device::isSleepRequested() const {
static std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Message::Type::WiVICommandResponse); static std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Message::Type::WiVICommandResponse);
// Hold this lock so the WiVI stack doesn't issue a WiVICommand at the same time as us // Hold this lock so the WiVI stack doesn't issue a WiVICommand at the same time as us
std::lock_guard<std::mutex> lk(wiviMutex); std::lock_guard<std::mutex> lk(wiviMutex);
std::lock_guard<std::mutex> lg(diskLock);
const auto generic = com->waitForMessageSync([this]() { const auto generic = com->waitForMessageSync([this]() {
// VSSAL sets bit0 to indicate that it's waiting to sleep, then // VSSAL sets bit0 to indicate that it's waiting to sleep, then
// it waits for Wireless neoVI to acknowledge by clearing it. // it waits for Wireless neoVI to acknowledge by clearing it.
@ -1135,6 +1144,7 @@ bool Device::allowSleep(bool remoteWakeup) {
static std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Message::Type::WiVICommandResponse); static std::shared_ptr<MessageFilter> filter = std::make_shared<MessageFilter>(Message::Type::WiVICommandResponse);
// Hold this lock so the WiVI stack doesn't issue a WiVICommand at the same time as us // Hold this lock so the WiVI stack doesn't issue a WiVICommand at the same time as us
std::lock_guard<std::mutex> lk(wiviMutex); std::lock_guard<std::mutex> lk(wiviMutex);
std::lock_guard<std::mutex> lg(diskLock);
const auto generic = com->waitForMessageSync([this, remoteWakeup]() { const auto generic = com->waitForMessageSync([this, remoteWakeup]() {
// VSSAL sets bit0 to indicate that it's waiting to sleep, then // VSSAL sets bit0 to indicate that it's waiting to sleep, then
// it waits for Wireless neoVI to acknowledge by clearing it. // it waits for Wireless neoVI to acknowledge by clearing it.