selectabletimer: add mutex to start() and stop()#614
Merged
qiluo-msft merged 3 commits intosonic-net:masterfrom May 11, 2022
Merged
selectabletimer: add mutex to start() and stop()#614qiluo-msft merged 3 commits intosonic-net:masterfrom
qiluo-msft merged 3 commits intosonic-net:masterfrom
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 <[email protected]>
This was referenced Apr 28, 2022
|
@zhangyanzhao @yxieca @qiluo-msft pls help signoff and merge |
qiluo-msft
reviewed
May 6, 2022
common/selectabletimer.cpp
Outdated
| SWSS_LOG_THROW("failed to create timerfd, errno: %s", strerror(errno)); | ||
| } | ||
| setInterval(interval); | ||
| m_alive = false; |
Contributor
qiluo-msft
reviewed
May 6, 2022
| @@ -36,22 +37,40 @@ SelectableTimer::~SelectableTimer() | |||
|
|
|||
| void SelectableTimer::start() | |||
Contributor
Contributor
Author
There was a problem hiding this comment.
Please refer to timer_ut.cpp: line 43-51
Signed-off-by: Dante Su <[email protected]>
Signed-off-by: Dante Su <[email protected]>
ds952811
commented
May 9, 2022
| EXPECT_EQ(value, 2); | ||
| } | ||
|
|
||
| TEST(DBConnector, selectabletimer) |
Contributor
Author
There was a problem hiding this comment.
Moved to timer_ut.cpp
qiluo-msft
reviewed
May 10, 2022
| ASSERT_EQ(result, Select::OBJECT); | ||
| ASSERT_EQ(sel, &timer); | ||
|
|
||
| // Check if the timer gets reset by subsequent timer.start() |
Contributor
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
There was a problem hiding this comment.
Do you mean original code will fail on this line?
ASSERT_EQ(result, Select::OBJECT);
Contributor
Author
There was a problem hiding this comment.
Yes, it'll fail at that line without the changes in the PR
qiluo-msft
approved these changes
May 11, 2022
itamar-talmon
pushed a commit
to itamar-talmon/sonic-swss-common
that referenced
this pull request
Jul 19, 2022
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()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 [email protected]