Commit 4d89c25f authored by Dominik Charousset's avatar Dominik Charousset

Add hooking API to testing scheduler API

parent 181c56ec
...@@ -102,7 +102,12 @@ public: ...@@ -102,7 +102,12 @@ public:
} }
/// Tries to execute a single event. /// Tries to execute a single event.
bool run_once(); bool try_run_once();
/// Deprecated. Use `try_run_once()` instead.
inline bool run_once() CAF_DEPRECATED {
return try_run_once();
}
/// Executes events until the job queue is empty and no pending timeouts are /// Executes events until the job queue is empty and no pending timeouts are
/// left. Returns the number of processed events. /// left. Returns the number of processed events.
...@@ -134,6 +139,10 @@ public: ...@@ -134,6 +139,10 @@ public:
inline_enqueues_ = num; inline_enqueues_ = num;
} }
/// The function used for inlining enqueue operations. The default predicate
/// calls `run()`.
std::function<void()> inlining_hook;
protected: protected:
void start() override; void start() override;
...@@ -143,6 +152,7 @@ protected: ...@@ -143,6 +152,7 @@ protected:
private: private:
size_t inline_enqueues_; size_t inline_enqueues_;
bool inside_inlined_enqueue;
}; };
} // namespace scheduler } // namespace scheduler
......
...@@ -95,7 +95,9 @@ private: ...@@ -95,7 +95,9 @@ private:
test_coordinator::test_coordinator(actor_system& sys) test_coordinator::test_coordinator(actor_system& sys)
: super(sys), : super(sys),
inline_enqueues_(0) { inline_enqueues_(0) {
// nop inlining_hook = [=] {
run();
};
} }
void test_coordinator::start() { void test_coordinator::start() {
dummy_worker worker{this}; dummy_worker worker{this};
...@@ -113,27 +115,16 @@ void test_coordinator::stop() { ...@@ -113,27 +115,16 @@ void test_coordinator::stop() {
void test_coordinator::enqueue(resumable* ptr) { void test_coordinator::enqueue(resumable* ptr) {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
if (inline_enqueues_ > 0) {
--inline_enqueues_;
CAF_LOG_DEBUG("inline actor execution, remaining:" << inline_enqueues_);
dummy_worker worker{this};
switch (ptr->resume(&worker, 1)) {
case resumable::resume_later:
enqueue(ptr);
break;
case resumable::done:
case resumable::awaiting_message:
intrusive_ptr_release(ptr);
break;
case resumable::shutdown_execution_unit:
break;
}
} else {
jobs.push_back(ptr); jobs.push_back(ptr);
if (!inside_inlined_enqueue && inline_enqueues_ > 0) {
--inline_enqueues_;
inside_inlined_enqueue = true;
inlining_hook();
inside_inlined_enqueue = false;
} }
} }
bool test_coordinator::run_once() { bool test_coordinator::try_run_once() {
if (jobs.empty()) if (jobs.empty())
return false; return false;
auto job = jobs.front(); auto job = jobs.front();
...@@ -155,7 +146,7 @@ bool test_coordinator::run_once() { ...@@ -155,7 +146,7 @@ bool test_coordinator::run_once() {
size_t test_coordinator::run(size_t max_count) { size_t test_coordinator::run(size_t max_count) {
size_t res = 0; size_t res = 0;
while (res < max_count && run_once()) while (res < max_count && try_run_once())
++res; ++res;
return res; return res;
} }
......
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