Revert "remove spinlocks"

This reverts commit 1670c26313.
This commit is contained in:
Nick Chan committed 2024-09-23 15:50:58 +08:00
1 parent ff94a8281d
commit d9dfefadcb
6 files changed
+34 -32

No files matched your search

+2 -6
View File
@@ -153,8 +153,6 @@ typedef unsigned char niarelap_file_t[];
extern unsigned int verbose;
pthread_cond_t spin;
extern char* pongo_path;
#ifdef TUI
extern bool tui_started;
@@ -174,7 +172,6 @@ extern uint64_t palerain_flags;
extern pthread_mutex_t log_mutex;
extern pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
pthread_cond_t spin;
extern int pongo_thr_running, dfuhelper_thr_running;
extern bool device_has_booted;
@@ -216,8 +213,8 @@ int issue_pongo_command(usb_device_handle_t, char*);
int tui(void);
int optparse(int argc, char* argv[]);
bool palerain_unblock(void);
bool palerain_block(void);
bool get_spin(void);
bool set_spin(bool val);
bool get_found_pongo(void);
void* pongo_helper(void* _);
bool set_found_pongo(bool val);
@@ -230,5 +227,4 @@ void io_stop(stuff_t *stuff);
void print_credits(void);
#endif
+11 -8
View File
@@ -100,7 +100,7 @@ int connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
printf("DisplayName: %s\n", dev.displayName);
device_has_booted = true;
palerain_unblock();
set_spin(0);
unsubscribe_cmd();
return 0;
}
@@ -115,7 +115,7 @@ int connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
devinfo_free(&dev);
if ((palerain_flags & palerain_option_enter_recovery)) {
device_has_booted = true;
palerain_unblock();
set_spin(0);
unsubscribe_cmd();
}
return 0;
@@ -226,7 +226,7 @@ void* connected_dfu_mode(struct irecv_device_info* info) {
if (IS_APPLE_HOME) {
step(2, 0, "Put device in upright orientation", NULL, 0);
}
palerain_unblock();
set_spin(0);
unsubscribe_cmd();
pthread_exit(NULL);
return NULL;
@@ -243,7 +243,7 @@ void device_event_cb(const usbmuxd_event_t *event, void* userdata) {
int ret = reboot_cmd(event->device.udid);
if (!ret) {
LOG(LOG_INFO, "Restarted device");
palerain_unblock();
set_spin(0);
unsubscribe_cmd();
}
pthread_exit(NULL);
@@ -274,7 +274,7 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
if (!ret) {
LOG(LOG_INFO, "Exited recovery mode");
device_has_booted = true;
palerain_unblock();
set_spin(0);
unsubscribe_cmd();
} else {
LOG(LOG_WARNING, "Could not exit recovery mode");
@@ -295,7 +295,7 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
printf("DisplayName: %s\n", info.display_name);
device_has_booted = true;
palerain_unblock();
set_spin(0);
unsubscribe_cmd();
}
if (dfuhelper_thr_running) pthread_cancel(dfuhelper_thread);
@@ -321,7 +321,7 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
printf("DisplayName: %s\n", info.display_name);
device_has_booted = true;
palerain_unblock();
set_spin(0);
unsubscribe_cmd();
}
if (dfuhelper_thr_running) pthread_cancel(dfuhelper_thread);
@@ -346,8 +346,11 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
void *dfuhelper(void* ptr) {
dfuhelper_thr_running = true;
set_spin(1);
subscribe_cmd(device_event_cb, irecv_device_event_cb);
palerain_block();
while (get_spin()) {
sleep(1);
};
dfuhelper_thr_running = false;
return 0;
}
+5 -8
View File
@@ -30,9 +30,8 @@
#include <paleinfo.h>
pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
pthread_cond_t spin;
bool found_pongo = 0;
bool spin, found_pongo = 0;
uint64_t ecid_wait_for_dfu = 0;
static bool get_locked_bool(bool* val, pthread_mutex_t* mutex) {
@@ -51,14 +50,12 @@ static bool set_locked_bool(bool* val, bool newval, pthread_mutex_t* mutex) {
return newval;
}
bool palerain_block(void) {
pthread_mutex_lock(&spin_mutex);
pthread_cond_wait(&spin, &spin_mutex);
pthread_mutex_unlock(&spin_mutex);
bool get_spin(void) {
return get_locked_bool(&spin, &spin_mutex);
}
bool palerain_unblock(void) {
pthread_cond_broadcast(&spin);
bool set_spin(bool newval) {
return set_locked_bool(&spin, newval, &spin_mutex);
}
bool get_found_pongo(void) {
+6 -4
View File
@@ -107,7 +107,6 @@ int palera1n(int argc, char *argv[], char *envp[]) {
pthread_mutex_init(&spin_mutex, NULL);
pthread_mutex_init(&found_pongo_mutex, NULL);
pthread_mutex_init(&ecid_dfu_wait_mutex, NULL);
pthread_cond_init(&spin, NULL);
if ((ret = build_checks())) return ret;
if ((ret = optparse(argc, argv))) goto cleanup;
if (!(palerain_flags & palerain_option_device_info) && (palerain_flags & palerain_option_palerain_version)) goto normal_exit;
@@ -141,7 +140,7 @@ int palera1n(int argc, char *argv[], char *envp[]) {
pthread_create(&pongo_thread, NULL, pongo_helper, NULL);
pthread_create(&dfuhelper_thread, NULL, dfuhelper, NULL);
pthread_join(dfuhelper_thread, NULL);
palerain_unblock();
set_spin(0);
if ((palerain_flags & (palerain_option_dfuhelper_only |
palerain_option_reboot_device |
palerain_option_exit_recovery |
@@ -155,10 +154,14 @@ int palera1n(int argc, char *argv[], char *envp[]) {
if ((palerain_flags & (palerain_option_pongo_exit | palerain_option_demote)))
goto normal_exit;
set_spin(1);
sleep(2);
pthread_create(&pongo_thread, NULL, pongo_helper, NULL);
pthread_join(pongo_thread, NULL);
palerain_block();
while (get_spin())
{
sleep(1);
}
normal_exit:
cleanup:
if (override_kpf.magic == OVERRIDE_MAGIC) {
@@ -178,7 +181,6 @@ cleanup:
pthread_mutex_destroy(&spin_mutex);
pthread_mutex_destroy(&found_pongo_mutex);
pthread_mutex_destroy(&ecid_dfu_wait_mutex);
pthread_cond_destroy(&spin);
return ret;
}
+7 -5
View File
@@ -25,7 +25,9 @@ void* pongo_helper(void* ptr) {
pongo_thr_running = 1;
pthread_cleanup_push(thr_cleanup, &pongo_thr_running);
wait_for_pongo();
palerain_block();
while (get_spin()) {
sleep(1);
}
pthread_cleanup_pop(1);
return NULL;
}
@@ -139,7 +141,7 @@ done:
#ifdef USE_LIBUSB
libusb_unref_device(arg->dev);
#endif
palerain_unblock();
set_spin(0);
return NULL;
}
@@ -234,7 +236,7 @@ void io_start(stuff_t *stuff)
if(r != 0)
{
ERR("pthread_create: %s", strerror(r));
palerain_unblock();
set_spin(0);
return;
}
pthread_join(stuff->th, NULL);
@@ -246,14 +248,14 @@ void io_stop(stuff_t *stuff)
if(r != 0)
{
ERR("pthread_cancel: %s", strerror(r));
palerain_unblock();
set_spin(0);
return;
}
r = pthread_join(stuff->th, NULL);
if(r != 0)
{
ERR("pthread_join: %s", strerror(r));
palerain_unblock();
set_spin(0);
return;
}
#ifdef USE_LIBUSB
+3 -1
View File
@@ -245,7 +245,9 @@ int wait_for_pongo(void) {
}
LostDevice(&stuff, lost);
// CFRunLoopRun();
palerain_block();
while (get_spin()) {
sleep(1);
}
CFRelease(cfdict);
return 0;
}