Commit aaf79543 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Make DrivableExecutor::drive and decendents noexcept.

Summary: Added noexcept to drive functionality of executors as exceptions should not be leaking from these operations.

Reviewed By: yfeldblum

Differential Revision: D6846415

fbshipit-source-id: 569819ef94d28c9c8c060cc8015247c416b8ab45
parent 10f39e11
...@@ -27,12 +27,12 @@ void TimedDrivableExecutor::add(Func callback) { ...@@ -27,12 +27,12 @@ void TimedDrivableExecutor::add(Func callback) {
queue_.enqueue(std::move(callback)); queue_.enqueue(std::move(callback));
} }
void TimedDrivableExecutor::drive() { void TimedDrivableExecutor::drive() noexcept {
wait(); wait();
run(); run();
} }
size_t TimedDrivableExecutor::run() { size_t TimedDrivableExecutor::run() noexcept {
size_t count = 0; size_t count = 0;
size_t n = queue_.size(); size_t n = queue_.size();
...@@ -52,7 +52,7 @@ size_t TimedDrivableExecutor::run() { ...@@ -52,7 +52,7 @@ size_t TimedDrivableExecutor::run() {
return count; return count;
} }
size_t TimedDrivableExecutor::drain() { size_t TimedDrivableExecutor::drain() noexcept {
size_t tasksRun = 0; size_t tasksRun = 0;
size_t tasksForSingleRun = 0; size_t tasksForSingleRun = 0;
while ((tasksForSingleRun = run()) != 0) { while ((tasksForSingleRun = run()) != 0) {
...@@ -61,7 +61,7 @@ size_t TimedDrivableExecutor::drain() { ...@@ -61,7 +61,7 @@ size_t TimedDrivableExecutor::drain() {
return tasksRun; return tasksRun;
} }
void TimedDrivableExecutor::wait() { void TimedDrivableExecutor::wait() noexcept {
if (!func_) { if (!func_) {
queue_.dequeue(func_); queue_.dequeue(func_);
} }
......
...@@ -30,11 +30,11 @@ namespace folly { ...@@ -30,11 +30,11 @@ namespace folly {
class TimedDrivableExecutor : public DrivableExecutor { class TimedDrivableExecutor : public DrivableExecutor {
public: public:
/// Implements DrivableExecutor /// Implements DrivableExecutor
void drive() override; void drive() noexcept override;
// Make progress if there is work to do and return true. Otherwise return // Make progress if there is work to do and return true. Otherwise return
// false. // false.
bool try_drive() { bool try_drive() noexcept {
return try_wait() && run() > 0; return try_wait() && run() > 0;
} }
...@@ -42,7 +42,8 @@ class TimedDrivableExecutor : public DrivableExecutor { ...@@ -42,7 +42,8 @@ class TimedDrivableExecutor : public DrivableExecutor {
// wait for a period of timeout for work to be enqueued. If no work is // wait for a period of timeout for work to be enqueued. If no work is
// enqueued by that point, it will return. // enqueued by that point, it will return.
template <typename Rep, typename Period> template <typename Rep, typename Period>
bool try_drive_for(const std::chrono::duration<Rep, Period>& timeout) { bool try_drive_for(
const std::chrono::duration<Rep, Period>& timeout) noexcept {
return try_wait_for(timeout) && run() > 0; return try_wait_for(timeout) && run() > 0;
} }
...@@ -51,7 +52,7 @@ class TimedDrivableExecutor : public DrivableExecutor { ...@@ -51,7 +52,7 @@ class TimedDrivableExecutor : public DrivableExecutor {
// that point, it will return. // that point, it will return.
template <typename Clock, typename Duration> template <typename Clock, typename Duration>
bool try_drive_until( bool try_drive_until(
const std::chrono::time_point<Clock, Duration>& deadline) { const std::chrono::time_point<Clock, Duration>& deadline) noexcept {
return try_wait_until(deadline) && run() > 0; return try_wait_until(deadline) && run() > 0;
} }
...@@ -63,7 +64,7 @@ class TimedDrivableExecutor : public DrivableExecutor { ...@@ -63,7 +64,7 @@ class TimedDrivableExecutor : public DrivableExecutor {
/// This is stable, it will not chase an ever-increasing tail of work. /// This is stable, it will not chase an ever-increasing tail of work.
/// This also means, there may be more work available to perform at the /// This also means, there may be more work available to perform at the
/// moment that this returns. /// moment that this returns.
size_t run(); size_t run() noexcept;
// Do work until there is no more work to do. // Do work until there is no more work to do.
// Returns the number of functions that were executed (maybe 0). // Returns the number of functions that were executed (maybe 0).
...@@ -71,26 +72,27 @@ class TimedDrivableExecutor : public DrivableExecutor { ...@@ -71,26 +72,27 @@ class TimedDrivableExecutor : public DrivableExecutor {
// work so should be used with care. // work so should be used with care.
// There will be no work available to perform at the moment that this // There will be no work available to perform at the moment that this
// returns. // returns.
size_t drain(); size_t drain() noexcept;
/// Wait for work to do. /// Wait for work to do.
void wait(); void wait() noexcept;
// Return true if there is work to do, false otherwise // Return true if there is work to do, false otherwise
bool try_wait() { bool try_wait() noexcept {
return func_ || queue_.try_dequeue(func_); return func_ || queue_.try_dequeue(func_);
} }
/// Wait for work to do or for a period of timeout, whichever is sooner. /// Wait for work to do or for a period of timeout, whichever is sooner.
template <typename Rep, typename Period> template <typename Rep, typename Period>
bool try_wait_for(const std::chrono::duration<Rep, Period>& timeout) { bool try_wait_for(
const std::chrono::duration<Rep, Period>& timeout) noexcept {
return func_ || queue_.try_dequeue_for(func_, timeout); return func_ || queue_.try_dequeue_for(func_, timeout);
} }
/// Wait for work to do or until deadline passes, whichever is sooner. /// Wait for work to do or until deadline passes, whichever is sooner.
template <typename Clock, typename Duration> template <typename Clock, typename Duration>
bool try_wait_until( bool try_wait_until(
const std::chrono::time_point<Clock, Duration>& deadline) { const std::chrono::time_point<Clock, Duration>& deadline) noexcept {
return func_ || queue_.try_dequeue_until(func_, deadline); return func_ || queue_.try_dequeue_until(func_, deadline);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment