Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curvefs/client: fix timer bug #1492

Merged
merged 1 commit into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/common/interruptible_sleeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class InterruptibleSleeper {
cv.notify_all();
}

void init() {
UniqueLock lock(m);
terminate = false;
}

private:
ConditionVariable cv;
Mutex m;
Expand Down
2 changes: 1 addition & 1 deletion src/common/wait_interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void WaitInterval::WaitForNextExcution() {
rest = (rest < 0) ? 0 : rest;

sleeper_.wait_for(std::chrono::milliseconds(rest));

sleeper_.init();
lastSend_ = TimeUtility::GetTimeofDayMs();
}

Expand Down
23 changes: 23 additions & 0 deletions test/common/wait_interval_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ TEST(WaitIntervalTest, test) {
ASSERT_EQ(5, count);
}

TEST(IntervalTest, signalTest) {
WaitInterval waitInterval;
waitInterval.Init(1000);

uint64_t start = TimeUtility::GetTimeofDayMs();
bool isSignal = true;
int count = 0;
while (true) {
waitInterval.WaitForNextExcution();
if (isSignal) {
sleep(1);
waitInterval.StopWait();
isSignal = false;
}
if (++count > 10) {
break;
}
}
uint64_t end = TimeUtility::GetTimeofDayMs();
uint64_t dur = end - start;
ASSERT_GT(dur, 5000);
}

} // namespace common
} // namespace curve