MCPcopy Create free account
hub / github.com/alibaba/async_simple / Executor

Class Executor

async_simple/Executor.h:72–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70class IOExecutor;
71
72class Executor {
73public:
74 // Context is an identification for the context where an executor
75 // should run. See checkin/checkout for details.
76 using Context = void *;
77 static constexpr Context NULLCTX = nullptr;
78
79 // A time duration in microseconds.
80 using Duration = std::chrono::duration<int64_t, std::micro>;
81
82 // The schedulable function. Func should accept no argument and
83 // return void.
84 using Func = std::function<void()>;
85 class TimeAwaitable;
86 class TimeAwaiter;
87
88 Executor(std::string name = "default") : _name(std::move(name)) {}
89 virtual ~Executor() {}
90
91 Executor(const Executor &) = delete;
92 Executor &operator=(const Executor &) = delete;
93
94 // Schedule a function.
95 // `schedule` would return false if schedule failed, which means function
96 // func will not be executed. In case schedule return true, the executor
97 // should guarantee that the func would be executed.
98 virtual bool schedule(Func func) = 0;
99
100 // 4-bits priority, less level is more important. Default
101 // value of async-simple schedule is DEFAULT. For scheduling level >=
102 // YIELD, if executor always execute the work immediately if other
103 // works, it may cause dead lock. are waiting.
104 enum class Priority {
105 HIGHEST = 0x0,
106 DEFAULT = 0x7,
107 YIELD = 0x8,
108 LOWEST = 0xF
109 };
110
111 // Low 16-bit of schedule_info is reserved for async-simple, and the lowest
112 // 4-bit is stand for priority level. The implementation of scheduling logic
113 // isn't necessary, which is determined by implementation. However, to avoid
114 // spinlock/yield deadlock, when priority level >= YIELD, scheduler
115 // can't always execute the work immediately when other works are
116 // waiting.
117 virtual bool schedule(Func func, uint64_t schedule_info) {
118 return schedule(std::move(func));
119 }
120
121 // Schedule a move only functor
122 bool schedule_move_only(util::move_only_function<void()> func) {
123 MoveWrapper<decltype(func)> tmp(std::move(func));
124 return schedule([func = tmp]() { func.get()(); });
125 }
126
127 bool schedule_move_only(util::move_only_function<void()> func,
128 uint64_t schedule_info) {
129 MoveWrapper<decltype(func)> tmp(std::move(func));

Callers 3

getFunction · 0.50
handler_work.hppFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected