Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: aebe06d10dc7
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 17971ba7bf48
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on May 2, 2021

  1. Restart of RecurringThread.

    pleroy committed May 2, 2021
    Copy the full SHA
    f54ae59 View commit details
  2. Merge pull request #2968 from pleroy/Restart

    Support for restarting a RecurringThread
    pleroy authored May 2, 2021
    Copy the full SHA
    17971ba View commit details
Showing with 10 additions and 0 deletions.
  1. +3 −0 base/recurring_thread.hpp
  2. +7 −0 base/recurring_thread_body.hpp
3 changes: 3 additions & 0 deletions base/recurring_thread.hpp
Original file line number Diff line number Diff line change
@@ -29,6 +29,9 @@ class BaseRecurringThread {
void Start();
void Stop();

// Stop followed by Start, atomically.
void Restart();

protected:
// Constructs a stoppable thread that runs no more frequently than at the
// specified |period| (and less frequently if no input was provided). At
7 changes: 7 additions & 0 deletions base/recurring_thread_body.hpp
Original file line number Diff line number Diff line change
@@ -21,6 +21,13 @@ inline void BaseRecurringThread::Stop() {
jthread_ = jthread();
}

inline void BaseRecurringThread::Restart() {
absl::MutexLock l(&jthread_lock_);
jthread_ = jthread();
jthread_ = MakeStoppableThread(
[this]() { Status const status = RepeatedlyRunAction(); });
}

inline BaseRecurringThread::BaseRecurringThread(
std::chrono::milliseconds const period)
: period_(period) {}