mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-22 21:28:59 +02:00
grab the now timestamp only when needed
This commit is contained in:
parent
1cd16da83e
commit
c94e2bdc8b
1 changed files with 2 additions and 4 deletions
|
@ -29,6 +29,7 @@
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
|
|
||||||
using namespace udt;
|
using namespace udt;
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
template <typename Mutex1, typename Mutex2>
|
template <typename Mutex1, typename Mutex2>
|
||||||
class DoubleLock {
|
class DoubleLock {
|
||||||
|
@ -303,15 +304,12 @@ void SendQueue::run() {
|
||||||
if (_state != State::Running || isInactive(sentAPacket)) {
|
if (_state != State::Running || isInactive(sentAPacket)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab the current HRC timestamp
|
|
||||||
const auto now = p_high_resolution_clock::now();
|
|
||||||
|
|
||||||
// push the next packet timestamp forwards by the current packet send period
|
// push the next packet timestamp forwards by the current packet send period
|
||||||
nextPacketTimestamp += std::chrono::microseconds(_packetSendPeriod);
|
nextPacketTimestamp += std::chrono::microseconds(_packetSendPeriod);
|
||||||
|
|
||||||
// sleep as long as we need until next packet send, if we can
|
// sleep as long as we need until next packet send, if we can
|
||||||
const auto timeToSleep = std::chrono::duration_cast<std::chrono::microseconds>(nextPacketTimestamp - now);
|
const auto timeToSleep = duration_cast<microseconds>(nextPacketTimestamp - p_high_resolution_clock::now());
|
||||||
|
|
||||||
std::this_thread::sleep_for(timeToSleep);
|
std::this_thread::sleep_for(timeToSleep);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue