Skip to content

Commit

Permalink
[core] CSync::wait_until is now mapped to CV::wait_until
Browse files Browse the repository at this point in the history
instead of wait_for. When C++11 sync is enabled, it will reduce the number of time conversions.
  • Loading branch information
maxsharabayko committed Dec 17, 2020
1 parent 4b7616a commit ba883c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion srtcore/core.cpp
Expand Up @@ -5773,7 +5773,7 @@ void *CUDT::tsbpd(void *param)
log << self->CONID() << "tsbpd: FUTURE PACKET seq=" << current_pkt_seq
<< " T=" << FormatTime(tsbpdtime) << " - waiting " << count_milliseconds(timediff) << "ms");
THREAD_PAUSED();
tsbpd_cc.wait_for(timediff);
tsbpd_cc.wait_until(tsbpdtime);
THREAD_RESUMED();
}
else
Expand Down
20 changes: 7 additions & 13 deletions srtcore/sync.h
Expand Up @@ -475,26 +475,20 @@ class CSync
/// Block the call until either @a timestamp time achieved
/// or the conditional is signaled.
/// @param [in] delay Maximum time to wait since the moment of the call
/// @retval true Resumed due to getting a CV signal
/// @retval false Resumed due to being past @a timestamp
/// @retval false if the relative timeout specified by rel_time expired,
/// @retval true if condition is signaled or spurious wake up.
bool wait_for(const steady_clock::duration& delay)
{
return m_cond->wait_for(*m_locker, delay);
}

// Wait until the given time is achieved. This actually
// refers to wait_for for the time remaining to achieve
// given time.
// Wait until the given time is achieved.
/// @param [in] exptime The target time to wait until.
/// @retval false if the target wait time is reached.
/// @retval true if condition is signal or spurious wake up.
bool wait_until(const steady_clock::time_point& exptime)
{
// This will work regardless as to which clock is in use. The time
// should be specified as steady_clock::time_point, so there's no
// question of the timer base.
steady_clock::time_point now = steady_clock::now();
if (now >= exptime)
return false; // timeout

return wait_for(exptime - now);
return m_cond->wait_until(*m_locker, exptime);
}

// Static ad-hoc version
Expand Down

0 comments on commit ba883c3

Please sign in to comment.