Skip to content

Commit

Permalink
Style: rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Dec 7, 2023
1 parent 91886e6 commit 48fec7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions coroio/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ struct TEvent {

template<typename T1, typename T2>
inline std::tuple<T1, T2>
GetDurationPair(TTime now, TTime deadline, std::chrono::milliseconds min_duration)
GetDurationPair(TTime now, TTime deadline, std::chrono::milliseconds maxDuration)
{
if (now > deadline) {
return std::make_tuple(T1(0), T2(0));
} else {
auto duration = (deadline - now);
if (duration > min_duration) {
duration = min_duration;
if (duration > maxDuration) {
duration = maxDuration;
}
auto part1 = std::chrono::duration_cast<T1>(duration);
duration -= part1;
Expand All @@ -62,9 +62,9 @@ GetDurationPair(TTime now, TTime deadline, std::chrono::milliseconds min_duratio
}
}

inline timeval GetTimeval(TTime now, TTime deadline, std::chrono::milliseconds min_duration)
inline timeval GetTimeval(TTime now, TTime deadline, std::chrono::milliseconds maxDuration)
{
auto [p1, p2] = GetDurationPair<std::chrono::seconds, std::chrono::microseconds>(now, deadline, min_duration);
auto [p1, p2] = GetDurationPair<std::chrono::seconds, std::chrono::microseconds>(now, deadline, maxDuration);
return {p1.count(), static_cast<int>(p2.count())};
}

Expand All @@ -73,9 +73,9 @@ inline int GetMillis(TTime now, TTime deadline, std::chrono::milliseconds min_du
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}

inline timespec GetTimespec(TTime now, TTime deadline, std::chrono::milliseconds min_duration)
inline timespec GetTimespec(TTime now, TTime deadline, std::chrono::milliseconds maxDuration)
{
auto [p1, p2] = GetDurationPair<std::chrono::seconds, std::chrono::nanoseconds>(now, deadline, min_duration);
auto [p1, p2] = GetDurationPair<std::chrono::seconds, std::chrono::nanoseconds>(now, deadline, maxDuration);
return {p1.count(), p2.count()};
}

Expand Down
16 changes: 8 additions & 8 deletions coroio/poller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ class TPollerBase {
}
}

void SetMinDuration(std::chrono::milliseconds minDuration) {
MinDuration_ = minDuration;
MinDurationTs_ = GetMinDuration(MinDuration_);
void SetMaxDuration(std::chrono::milliseconds maxDuration) {
MaxDuration_ = maxDuration;
MaxDurationTs_ = GetMaxDuration(MaxDuration_);
}

protected:
timespec GetTimeout() const {
return Timers_.empty()
? MinDurationTs_
? MaxDurationTs_
: Timers_.top().Deadline == TTime{}
? timespec {0, 0}
: GetTimespec(TClock::now(), Timers_.top().Deadline, MinDuration_);
: GetTimespec(TClock::now(), Timers_.top().Deadline, MaxDuration_);
}

static constexpr timespec GetMinDuration(std::chrono::milliseconds duration) {
static constexpr timespec GetMaxDuration(std::chrono::milliseconds duration) {
auto p1 = std::chrono::duration_cast<std::chrono::seconds>(duration);
auto p2 = std::chrono::duration_cast<std::chrono::nanoseconds>(duration - p1);
return {p1.count(), p2.count()};
Expand Down Expand Up @@ -136,8 +136,8 @@ class TPollerBase {
std::vector<TEvent> ReadyEvents_;
std::priority_queue<TTimer> Timers_;
TTime LastTimersProcessTime_;
std::chrono::milliseconds MinDuration_ = std::chrono::milliseconds(100);
timespec MinDurationTs_ = GetMinDuration(MinDuration_);
std::chrono::milliseconds MaxDuration_ = std::chrono::milliseconds(100);
timespec MaxDurationTs_ = GetMaxDuration(MaxDuration_);
};

} // namespace NNet

0 comments on commit 48fec7d

Please sign in to comment.