From 3d0dcb2a17aa08d45df5ce25de68362442c80e86 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 19 Nov 2022 12:11:03 +0800 Subject: [PATCH] Windows: Support run in single thread mode. --- trunk/auto/auto_headers.sh | 5 +++++ trunk/auto/options.sh | 4 ++++ trunk/src/main/srs_main_server.cpp | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/trunk/auto/auto_headers.sh b/trunk/auto/auto_headers.sh index 53650def12..42cb23da77 100755 --- a/trunk/auto/auto_headers.sh +++ b/trunk/auto/auto_headers.sh @@ -163,6 +163,11 @@ if [[ $SRS_LOG_TRACE == YES ]]; then else srs_undefine_macro "SRS_TRACE" $SRS_AUTO_HEADERS_H fi +if [[ $SRS_SINGLE_THREAD == YES ]]; then + srs_define_macro "SRS_SINGLE_THREAD" $SRS_AUTO_HEADERS_H +else + srs_undefine_macro "SRS_SINGLE_THREAD" $SRS_AUTO_HEADERS_H +fi if [[ $SRS_LOG_LEVEL_V2 == YES ]]; then srs_define_macro "SRS_LOG_LEVEL_V2" $SRS_AUTO_HEADERS_H else diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index 7ddbe8e93a..d1bd048869 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -70,6 +70,7 @@ SRS_BUILD_TAG= # Set the object files tag name. SRS_CLEAN=YES # Whether do "make clean" when configure. SRS_SIMULATOR=NO # Whether enable RTC simulate API. SRS_GENERATE_OBJS=NO # Whether generate objs and quit. +SRS_SINGLE_THREAD=NO # Whether force single thread mode. # ################################################################ # Performance options. @@ -184,6 +185,7 @@ Experts: --clean=on|off Whether do 'make clean' when configure. Default: $(value2switch $SRS_CLEAN) --simulator=on|off RTC: Whether enable network simulator. Default: $(value2switch $SRS_SIMULATOR) --generate-objs=on|off RTC: Whether generate objs and quit. Default: $(value2switch $SRS_GENERATE_OBJS) + --single-thread=on|off Whether force single thread mode. Default: $(value2switch $SRS_SINGLE_THREAD) --build-tag= Set the build object directory suffix. Workflow: @@ -298,6 +300,7 @@ function parse_user_option() { --rtc) SRS_RTC=$(switch2value $value) ;; --simulator) SRS_SIMULATOR=$(switch2value $value) ;; --generate-objs) SRS_GENERATE_OBJS=$(switch2value $value) ;; + --single-thread) SRS_SINGLE_THREAD=$(switch2value $value) ;; --ffmpeg-fit) SRS_FFMPEG_FIT=$(switch2value $value) ;; --gb28181) SRS_GB28181=$(switch2value $value) ;; @@ -586,6 +589,7 @@ function regenerate_options() { SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --debug-stats=$(value2switch $SRS_DEBUG_STATS)" SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cross-build=$(value2switch $SRS_CROSS_BUILD)" SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --sanitizer=$(value2switch $SRS_SANITIZER)" + SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --single-thread=$(value2switch $SRS_SINGLE_THREAD)" if [[ $SRS_CROSS_BUILD_ARCH != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --arch=$SRS_CROSS_BUILD_ARCH"; fi if [[ $SRS_CROSS_BUILD_CPU != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --cpu=$SRS_CROSS_BUILD_CPU"; fi if [[ $SRS_CROSS_BUILD_HOST != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --host=$SRS_CROSS_BUILD_HOST"; fi diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 66f6c642dc..460a768690 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -475,6 +475,10 @@ srs_error_t run_directly_or_daemon() srs_error_t run_hybrid_server(void* arg); srs_error_t run_in_thread_pool() { +#ifdef SRS_SINGLE_THREAD + srs_trace("Run in single thread mode"); + return run_hybrid_server(NULL); +#else srs_error_t err = srs_success; // Initialize the thread pool. @@ -490,6 +494,7 @@ srs_error_t run_in_thread_pool() srs_trace("Pool: Start threads primordial=1, hybrids=1 ok"); return _srs_thread_pool->run(); +#endif } #include