boardd: check do_exit in usb_retry_connect (#20007)

pull/20058/head
Dean Lee 4 years ago committed by GitHub
parent e9c4a75a5c
commit 2a935a2010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      selfdrive/boardd/boardd.cc

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

Loading…
Cancel
Save