From df1eca10fbbcf566e20f2729a1fc5d280f308306 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 11 Feb 2021 22:49:54 +0800 Subject: [PATCH] For #2194, yield for timer, for rtc publisher --- trunk/src/app/srs_app_listener.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/trunk/src/app/srs_app_listener.cpp b/trunk/src/app/srs_app_listener.cpp index a07ddc7cb..918ea91f7 100755 --- a/trunk/src/app/srs_app_listener.cpp +++ b/trunk/src/app/srs_app_listener.cpp @@ -593,7 +593,10 @@ srs_error_t SrsUdpMuxListener::cycle() // and the size is not determined, so we think there is at least one copy, // and we can reuse the plaintext h264/opus with players when got plaintext. SrsUdpMuxSocket skt(lfd); - + + // How many messages to run a yield. + uint32_t nn_msgs_for_yield = 0; + while (true) { if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "udp listener"); @@ -660,7 +663,14 @@ srs_error_t SrsUdpMuxListener::cycle() if (SrsUdpPacketRecvCycleInterval > 0) { srs_usleep(SrsUdpPacketRecvCycleInterval); - } + } + + // Yield to another coroutines. + // @see https://github.com/ossrs/srs/issues/2194#issuecomment-777485531 + if (++nn_msgs_for_yield > 10) { + nn_msgs_for_yield = 0; + srs_thread_yield(); + } } return err;