fix races

This commit is contained in:
Nick Chan committed 2023-01-30 21:41:15 +08:00
1 parent 9f14da315b
commit 95b0b63a98
7 files changed
+129 -27

No files matched your search

+10 -2
View File
@@ -88,6 +88,9 @@ bool use_tui = false;
int palera1n(int argc, char *argv[]) {
int ret = 0;
pthread_mutex_init(&log_mutex, NULL);
pthread_mutex_init(&spin_mutex, NULL);
pthread_mutex_init(&found_pongo_mutex, NULL);
pthread_mutex_init(&ecid_dfu_wait_mutex, NULL);
if ((ret = build_checks())) return ret;
if ((ret = optparse(argc, argv))) goto cleanup;
if (palerain_version) goto normal_exit;
@@ -111,13 +114,13 @@ int palera1n(int argc, char *argv[]) {
if (pongo_exit || demote)
goto normal_exit;
pongo:
spin = true;
set_spin(1);
if (do_pongo_sleep)
sleep(2);
else
LOG(LOG_INFO, "Waiting for PongoOS devices...");
wait_for_pongo();
while (spin)
while (get_spin())
{
sleep(1);
}
@@ -156,9 +159,14 @@ cleanup:
munmap(override_overlay.ptr, (size_t)override_overlay.len);
close(override_overlay.fd);
}
pthread_mutex_destroy(&log_mutex);
pthread_mutex_destroy(&spin_mutex);
pthread_mutex_destroy(&found_pongo_mutex);
pthread_mutex_destroy(&ecid_dfu_wait_mutex);
return ret;
}
int main (int argc, char* argv[]) {
return palera1n(argc, argv);
}