1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 20:01:56 +00:00

For #2194, yield for timer, for rtc player

This commit is contained in:
winlin 2021-02-11 23:10:08 +08:00
parent 5a28e658a4
commit ccb79bc7eb
2 changed files with 11 additions and 1 deletions

View file

@ -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;
@ -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;
}

View file

@ -138,6 +138,8 @@ public:
class SrsUdpMuxSocket
{
private:
// For sender yield only.
uint32_t nn_msgs_for_yield_;
std::map<uint32_t, std::string> cache_;
SrsBuffer* cache_buffer_;
private: