2 * Copyright 2018-present Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/executors/TimedDrivableExecutor.h>
26 void TimedDrivableExecutor::add(Func callback) {
27 queue_.enqueue(std::move(callback));
30 void TimedDrivableExecutor::drive() {
35 size_t TimedDrivableExecutor::run() {
37 size_t n = queue_.size();
39 // If we have waited already, then func_ may have a value
41 auto f = std::move(func_);
46 while (count < n && queue_.try_dequeue(func_)) {
47 auto f = std::move(func_);
55 size_t TimedDrivableExecutor::drain() {
57 size_t tasksForSingleRun = 0;
58 while ((tasksForSingleRun = run()) != 0) {
59 tasksRun += tasksForSingleRun;
64 void TimedDrivableExecutor::wait() {
66 queue_.dequeue(func_);