From e9240f6804764b2b4d7163566cd6d5cc0226f865 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 6 Sep 2024 23:08:08 +0200 Subject: [PATCH] Expose main thread id This will allow to assert that a function is called from the main thread. PR #5270 --- app/src/main.c | 4 ++++ app/src/util/thread.c | 2 ++ app/src/util/thread.h | 2 ++ 3 files changed, 8 insertions(+) diff --git a/app/src/main.c b/app/src/main.c index 6050de11..8bbd074f 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -16,6 +16,7 @@ #include "usb/scrcpy_otg.h" #include "util/log.h" #include "util/net.h" +#include "util/thread.h" #include "version.h" #ifdef _WIN32 @@ -67,6 +68,9 @@ 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_ALL av_register_all(); #endif diff --git a/app/src/util/thread.c b/app/src/util/thread.c index 94921fb7..9679dfff 100644 --- a/app/src/util/thread.c +++ b/app/src/util/thread.c @@ -6,6 +6,8 @@ #include "log.h" +sc_thread_id SC_MAIN_THREAD_ID; + bool sc_thread_create(sc_thread *thread, sc_thread_fn fn, const char *name, void *userdata) { diff --git a/app/src/util/thread.h b/app/src/util/thread.h index 4183adac..3d544046 100644 --- a/app/src/util/thread.h +++ b/app/src/util/thread.h @@ -39,6 +39,8 @@ typedef struct sc_cond { SDL_cond *cond; } sc_cond; +extern sc_thread_id SC_MAIN_THREAD_ID; + bool sc_thread_create(sc_thread *thread, sc_thread_fn fn, const char *name, void *userdata);