Files
nearby/cpp/platform_v2/impl/g3/scheduled_executor.h
T
Alexey Polyudov 5142ef11af Roll forward to cl/318932159
Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: Ia0cddfc8cf46c66d5739bdb45ab7825422912082
2020-06-30 00:27:57 -07:00

46 lines
1.2 KiB
C++

#ifndef PLATFORM_V2_IMPL_G3_SCHEDULED_EXECUTOR_H_
#define PLATFORM_V2_IMPL_G3_SCHEDULED_EXECUTOR_H_
#include <atomic>
#include <memory>
#include "platform_v2/api/cancelable.h"
#include "platform_v2/api/scheduled_executor.h"
#include "platform_v2/base/runnable.h"
#include "platform_v2/impl/g3/single_thread_executor.h"
#include "absl/time/clock.h"
#include "thread/threadpool.h"
namespace location {
namespace nearby {
namespace g3 {
// An Executor that reuses a fixed number of threads operating off a shared
// unbounded queue.
class ScheduledExecutor final : public api::ScheduledExecutor {
public:
ScheduledExecutor() = default;
~ScheduledExecutor() override {
executor_.Shutdown();
}
void Execute(Runnable&& runnable) override {
executor_.Execute(std::move(runnable));
}
std::shared_ptr<api::Cancelable> Schedule(Runnable&& runnable,
absl::Duration delay) override;
void Shutdown() override { executor_.Shutdown(); }
int GetTid(int index) const override {
return executor_.GetTid(index);
}
private:
SingleThreadExecutor executor_;
};
} // namespace g3
} // namespace nearby
} // namespace location
#endif // PLATFORM_V2_IMPL_G3_SCHEDULED_EXECUTOR_H_