Display and control your Android device
Simplify main thread detection
Romain Vimont70e4078b022d
diff --git a/app/src/events.c b/app/src/events.cindex 5269bdbc..3dc3dd7d 100644--- a/app/src/events.c+++ b/app/src/events.c@@ -54,7 +54,7 @@ task_event_filter(void *userdata, SDL_Event *event) {voidsc_reject_new_runnables(void) {- assert(sc_thread_get_id() == SC_MAIN_THREAD_ID);+ assert(sc_thread_is_main());SDL_SetEventFilter(task_event_filter, NULL);}diff --git a/app/src/main.c b/app/src/main.cindex d2dbef69..1de8d874 100644--- a/app/src/main.c+++ b/app/src/main.c@@ -15,7 +15,6 @@#endif#include "util/log.h"#include "util/net.h"-#include "util/thread.h"#include "version.h"#ifdef _WIN32@@ -67,9 +66,6 @@ main_scrcpy(int argc, char *argv[]) {goto end;}- // The current thread is the main thread- SC_MAIN_THREAD_ID = sc_thread_get_id();-#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALLav_register_all();#endifdiff --git a/app/src/receiver.c b/app/src/receiver.cindex 659f443f..89666256 100644--- a/app/src/receiver.c+++ b/app/src/receiver.c@@ -44,7 +44,7 @@ sc_receiver_destroy(struct sc_receiver *receiver) {static voidtask_set_clipboard(void *userdata) {- assert(sc_thread_get_id() == SC_MAIN_THREAD_ID);+ assert(sc_thread_is_main());char *text = userdata;@@ -67,7 +67,7 @@ task_set_clipboard(void *userdata) {static voidtask_uhid_output(void *userdata) {- assert(sc_thread_get_id() == SC_MAIN_THREAD_ID);+ assert(sc_thread_is_main());struct sc_uhid_output_task_data *data = userdata;diff --git a/app/src/uhid/keyboard_uhid.c b/app/src/uhid/keyboard_uhid.cindex d8337df0..d381bfd7 100644--- a/app/src/uhid/keyboard_uhid.c+++ b/app/src/uhid/keyboard_uhid.c@@ -60,7 +60,7 @@ sc_key_processor_process_key(struct sc_key_processor *kp,uint64_t ack_to_wait) {(void) ack_to_wait;- assert(sc_thread_get_id() == SC_MAIN_THREAD_ID);+ assert(sc_thread_is_main());if (event->repeat) {// In USB HID protocol, key repeat is handled by the host (Android), so@@ -104,7 +104,7 @@ sc_keyboard_uhid_to_sc_mod(uint8_t hid_led) {voidsc_keyboard_uhid_process_hid_output(struct sc_keyboard_uhid *kb,const uint8_t *data, size_t size) {- assert(sc_thread_get_id() == SC_MAIN_THREAD_ID);+ assert(sc_thread_is_main());assert(size);diff --git a/app/src/util/thread.c b/app/src/util/thread.cindex dce189bd..22e93202 100644--- a/app/src/util/thread.c+++ b/app/src/util/thread.c@@ -4,6 +4,7 @@#include <stdint.h>#include <stdlib.h>#include <string.h>+#include <SDL3/SDL_init.h>#include <SDL3/SDL_mutex.h>#include "util/log.h"@@ -106,6 +107,11 @@ sc_thread_get_id(void) {return SDL_GetCurrentThreadID();}+bool+sc_thread_is_main(void) {+ return SDL_IsMainThread();+}+#ifndef NDEBUGboolsc_mutex_held(struct sc_mutex *mutex) {diff --git a/app/src/util/thread.h b/app/src/util/thread.hindex 13734bdc..7f47af4d 100644--- a/app/src/util/thread.h+++ b/app/src/util/thread.h@@ -39,8 +39,6 @@ typedef struct sc_cond {SDL_Condition *cond;} sc_cond;-extern sc_thread_id SC_MAIN_THREAD_ID;-boolsc_thread_create(sc_thread *thread, sc_thread_fn fn, const char *name,void *userdata);@@ -66,6 +64,9 @@ sc_mutex_unlock(sc_mutex *mutex);sc_thread_idsc_thread_get_id(void);+bool+sc_thread_is_main(void);+#ifndef NDEBUGboolsc_mutex_held(struct sc_mutex *mutex);