boardd: check do_exit in usb_retry_connect (#20007)

albatross
Dean Lee 2021-02-08 19:01:12 +08:00 committed by GitHub
parent e9c4a75a5c
commit 2a935a2010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 12 deletions

View File

@ -36,7 +36,7 @@
#define SATURATE_IL 1600
#define NIBBLE_TO_HEX(n) ((n) < 10 ? (n) + '0' : ((n) - 10) + 'a')
Panda * panda = NULL;
Panda * panda = nullptr;
std::atomic<bool> safety_setter_thread_running(false);
std::atomic<bool> ignition(false);
@ -121,7 +121,7 @@ bool usb_connect() {
std::unique_ptr<Panda> tmp_panda;
try {
assert(panda == NULL);
assert(panda == nullptr);
tmp_panda = std::make_unique<Panda>();
} catch (std::exception &e) {
return false;
@ -180,10 +180,13 @@ bool usb_connect() {
}
// must be called before threads or with mutex
void usb_retry_connect() {
static bool usb_retry_connect() {
LOGW("attempting to connect");
while (!usb_connect()) { util::sleep_for(100); }
LOGW("connected to board");
while (!do_exit && !usb_connect()) { util::sleep_for(100); }
if (panda) {
LOGW("connected to board");
}
return !do_exit;
}
void can_recv(PubMaster &pm) {
@ -523,16 +526,16 @@ int main() {
threads.push_back(std::thread(can_health_thread, getenv("STARTED") != nullptr));
// connect to the board
usb_retry_connect();
threads.push_back(std::thread(can_send_thread, getenv("FAKESEND") != nullptr));
threads.push_back(std::thread(can_recv_thread));
threads.push_back(std::thread(hardware_control_thread));
threads.push_back(std::thread(pigeon_thread));
if (usb_retry_connect()) {
threads.push_back(std::thread(can_send_thread, getenv("FAKESEND") != nullptr));
threads.push_back(std::thread(can_recv_thread));
threads.push_back(std::thread(hardware_control_thread));
threads.push_back(std::thread(pigeon_thread));
}
for (auto &t : threads) t.join();
delete panda;
panda = NULL;
panda = nullptr;
}
}