Skip to content

Commit

Permalink
curvefs/client: fix timer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhongsong committed May 27, 2022
1 parent fc2a7dd commit 433a39b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
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

0 comments on commit 433a39b

Please sign in to comment.