Skip to content

Commit

Permalink
For #2194, yield for timer, for rtc publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 19, 2021
1 parent a049ce3 commit df1eca1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions trunk/src/app/srs_app_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit df1eca1

Please sign in to comment.