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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
||
SelectableTimer::~SelectableTimer() | ||
|
@@ -36,22 +37,40 @@ SelectableTimer::~SelectableTimer() | |
|
||
void SelectableTimer::start() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Please refer to timer_ut.cpp: line 43-51 |
||
{ | ||
// Set the timer interval and the timer is automatically started | ||
int rc = timerfd_settime(m_tfd, 0, &m_interval, NULL); | ||
if (rc == -1) | ||
m_mutex.lock(); | ||
if (!m_alive) | ||
{ | ||
SWSS_LOG_THROW("failed to set timerfd, errno: %s", strerror(errno)); | ||
// Set the timer interval and the timer is automatically started | ||
int rc = timerfd_settime(m_tfd, 0, &m_interval, NULL); | ||
if (rc == -1) | ||
{ | ||
SWSS_LOG_THROW("failed to set timerfd, errno: %s", strerror(errno)); | ||
} | ||
else | ||
{ | ||
m_alive = true; | ||
} | ||
} | ||
m_mutex.unlock(); | ||
} | ||
|
||
void SelectableTimer::stop() | ||
{ | ||
// Set the timer interval and the timer is automatically started | ||
int rc = timerfd_settime(m_tfd, 0, &m_zero, NULL); | ||
if (rc == -1) | ||
m_mutex.lock(); | ||
if (m_alive) | ||
{ | ||
SWSS_LOG_THROW("failed to set timerfd to zero, errno: %s", strerror(errno)); | ||
// Set the timer interval and the timer is automatically started | ||
int rc = timerfd_settime(m_tfd, 0, &m_zero, NULL); | ||
if (rc == -1) | ||
{ | ||
SWSS_LOG_THROW("failed to set timerfd to zero, errno: %s", strerror(errno)); | ||
} | ||
else | ||
{ | ||
m_alive = false; | ||
} | ||
} | ||
m_mutex.unlock(); | ||
} | ||
|
||
void SelectableTimer::reset() | ||
|
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.
better name
m_running
. #ClosedThere 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