Skip to content

Commit

Permalink
For #2194, yield for timer, for rtc player
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 19, 2021
1 parent df1eca1 commit ebcba14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion trunk/src/app/srs_app_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ srs_error_t SrsTcpListener::cycle()

SrsUdpMuxSocket::SrsUdpMuxSocket(srs_netfd_t fd)
{
nn_msgs_for_yield_ = 0;
nb_buf = SRS_UDP_MAX_PACKET_SIZE;
buf = new char[nb_buf];
nread = 0;
Expand Down Expand Up @@ -359,7 +360,14 @@ srs_error_t SrsUdpMuxSocket::sendto(void* data, int size, srs_utime_t timeout)
}

return srs_error_new(ERROR_SOCKET_WRITE, "sendto");
}
}

// Yield to another coroutines.
// @see https://github.com/ossrs/srs/issues/2194#issuecomment-777542162
if (++nn_msgs_for_yield_ > 20) {
nn_msgs_for_yield_ = 0;
srs_thread_yield();
}

return err;
}
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class SrsTcpListener : public ISrsCoroutineHandler
class SrsUdpMuxSocket
{
private:
// For sender yield only.
uint32_t nn_msgs_for_yield_;
std::map<uint32_t, std::string> cache_;
SrsBuffer* cache_buffer_;
private:
Expand Down

0 comments on commit ebcba14

Please sign in to comment.