From b38a9dedd3eac664a3f0f85ea7938ff04c7148fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Tue, 19 Sep 2023 09:03:33 -0700 Subject: [PATCH] Extract task execution to a separate method in RuntimeScheduler (#37881) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37881 Small refactor in preparation to add systrace markers for several methods in RuntimeScheduler. Changelog: [internal] Reviewed By: rshest Differential Revision: D46556398 fbshipit-source-id: a0b92ea9173a55ec5a845bcfa278018ec3349e1f --- .../runtimescheduler/RuntimeScheduler.cpp | 40 +++++++++---------- .../runtimescheduler/RuntimeScheduler.h | 5 +++ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp index 1141ba9bbc2..79ac8ef245c 100644 --- a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp +++ b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp @@ -106,17 +106,7 @@ void RuntimeScheduler::callExpiredTasks(jsi::Runtime& runtime) { break; } - currentPriority_ = topPriorityTask->priority; - auto result = topPriorityTask->execute(runtime, didUserCallbackTimeout); - - if (result.isObject() && result.getObject(runtime).isFunction(runtime)) { - topPriorityTask->callback = - result.getObject(runtime).getFunction(runtime); - } else { - if (taskQueue_.top() == topPriorityTask) { - taskQueue_.pop(); - } - } + executeTask(runtime, topPriorityTask, didUserCallbackTimeout); } } catch (jsi::JSError& error) { handleFatalError(runtime, error); @@ -151,17 +141,7 @@ void RuntimeScheduler::startWorkLoop(jsi::Runtime& runtime) const { break; } - currentPriority_ = topPriorityTask->priority; - auto result = topPriorityTask->execute(runtime, didUserCallbackTimeout); - - if (result.isObject() && result.getObject(runtime).isFunction(runtime)) { - topPriorityTask->callback = - result.getObject(runtime).getFunction(runtime); - } else { - if (taskQueue_.top() == topPriorityTask) { - taskQueue_.pop(); - } - } + executeTask(runtime, topPriorityTask, didUserCallbackTimeout); } } catch (jsi::JSError& error) { handleFatalError(runtime, error); @@ -171,4 +151,20 @@ void RuntimeScheduler::startWorkLoop(jsi::Runtime& runtime) const { isPerformingWork_ = false; } +void RuntimeScheduler::executeTask( + jsi::Runtime& runtime, + std::shared_ptr task, + bool didUserCallbackTimeout) const { + currentPriority_ = task->priority; + auto result = task->execute(runtime, didUserCallbackTimeout); + + if (result.isObject() && result.getObject(runtime).isFunction(runtime)) { + task->callback = result.getObject(runtime).getFunction(runtime); + } else { + if (taskQueue_.top() == task) { + taskQueue_.pop(); + } + } +} + } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h index a209f2f36fe..7bd1cb10318 100644 --- a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h +++ b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.h @@ -133,6 +133,11 @@ class RuntimeScheduler final { */ void scheduleWorkLoopIfNecessary() const; + void executeTask( + jsi::Runtime& runtime, + std::shared_ptr task, + bool didUserCallbackTimeout) const; + /* * Returns a time point representing the current point in time. May be called * from multiple threads.