2 * Copyright 2014-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.
26 class LoopController {
28 typedef std::chrono::steady_clock Clock;
29 typedef std::chrono::time_point<Clock> TimePoint;
31 virtual ~LoopController() {}
34 * Called by FiberManager to associate itself with the LoopController.
36 virtual void setFiberManager(FiberManager*) = 0;
39 * Called by FiberManager to schedule the loop function run
40 * at some point in the future.
42 virtual void schedule() = 0;
45 * Run FiberManager loopUntilNoReadyImpl(). May have additional logic specific
46 * to a LoopController.
48 virtual void runLoop() = 0;
51 * Same as schedule(), but safe to call from any thread.
52 * Runs func and only schedules if func returned true.
54 virtual void scheduleThreadSafe(std::function<bool()> func) = 0;
57 * Called by FiberManager to cancel a previously scheduled
60 virtual void cancel() = 0;
63 * Called by FiberManager to schedule some function to be run at some time.
65 virtual void timedSchedule(std::function<void()> func, TimePoint time) = 0;