boardd: check do_exit in usb_retry_connect (#20007)

old-commit-hash: 2a935a2010
commatwo_master
Dean Lee 4 years ago committed by GitHub
parent c8bcf66cd5
commit 31a811ca45
  1. 17
      selfdrive/boardd/boardd.cc

@ -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,11 +180,14 @@ 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); }
while (!do_exit && !usb_connect()) { util::sleep_for(100); }
if (panda) {
LOGW("connected to board");
}
return !do_exit;
}
void can_recv(PubMaster &pm) {
kj::Array<capnp::word> can_data;
@ -523,16 +526,16 @@ int main() {
threads.push_back(std::thread(can_health_thread, getenv("STARTED") != nullptr));
// 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_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;
}
}

Loading…
Cancel
Save