-
Notifications
You must be signed in to change notification settings - Fork 265
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
selectabletimer: add mutex to start() and stop() #614
Conversation
Add mutex protection to avoid having the timer expiration reset due to subsequent calls of start() Avoid having the timer expiration reset due to subsequent calls of start() Add mutex protection to start() and stop() Signed-off-by: Dante Su <dante.su@broadcom.com>
@zhangyanzhao @yxieca @qiluo-msft pls help signoff and merge |
common/selectabletimer.cpp
Outdated
@@ -21,6 +21,7 @@ SelectableTimer::SelectableTimer(const timespec& interval, int pri) | |||
SWSS_LOG_THROW("failed to create timerfd, errno: %s", strerror(errno)); | |||
} | |||
setInterval(interval); | |||
m_alive = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -36,22 +37,40 @@ SelectableTimer::~SelectableTimer() | |||
|
|||
void SelectableTimer::start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer to timer_ut.cpp: line 43-51
Signed-off-by: Dante Su <dante.su@broadcom.com>
Signed-off-by: Dante Su <dante.su@broadcom.com>
@@ -653,42 +653,6 @@ TEST(DBConnector, selectableevent) | |||
EXPECT_EQ(value, 2); | |||
} | |||
|
|||
TEST(DBConnector, selectabletimer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to timer_ut.cpp
ASSERT_EQ(result, Select::OBJECT); | ||
ASSERT_EQ(sel, &timer); | ||
|
||
// Check if the timer gets reset by subsequent timer.start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of original code, since the timer is created with flag=0, a relative timer is started, and everytime that timer.start() gets invoked, timerfd_settime() will reset the timeout based on the current timestamp, hence it will cause unexpected delay here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean original code will fail on this line?
ASSERT_EQ(result, Select::OBJECT);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it'll fail at that line without the changes in the PR
Add mutex protection to avoid having the timer expiration reset due to subsequent calls of start() Avoid having the timer expiration reset due to subsequent calls of start() Add mutex protection to start() and stop()
Add mutex protection to avoid having the timer expiration reset due to
subsequent calls of start()
Avoid having the timer expiration reset due to subsequent calls of start()
Add mutex protection to start() and stop()
Signed-off-by: Dante Su dante.su@broadcom.com