From 319aaf3a49b8c640002ac678ad844641a6d80ea1 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sun, 1 Jan 2023 18:08:25 +0800 Subject: [PATCH] Renaming performFunctionInCocosThread to runOnAxmolThread --- core/base/CCScheduler.cpp | 14 +++++++------- core/base/CCScheduler.h | 14 ++++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/core/base/CCScheduler.cpp b/core/base/CCScheduler.cpp index b2f943f019..f294e70155 100644 --- a/core/base/CCScheduler.cpp +++ b/core/base/CCScheduler.cpp @@ -264,7 +264,7 @@ Scheduler::Scheduler() #endif { // I don't expect to have more than 30 functions to all per frame - _functionsToPerform.reserve(30); + _actionsToPerform.reserve(30); } Scheduler::~Scheduler() @@ -812,16 +812,16 @@ void Scheduler::resumeTargets(const std::set& targetsToResume) } } -void Scheduler::performFunctionInCocosThread(std::function function) +void Scheduler::runOnAxmolThread(std::function action) { std::lock_guard lock(_performMutex); - _functionsToPerform.emplace_back(std::move(function)); + _actionsToPerform.emplace_back(std::move(action)); } -void Scheduler::removeAllFunctionsToBePerformedInCocosThread() +void Scheduler::removeAllPendingActions() { std::unique_lock lock(_performMutex); - _functionsToPerform.clear(); + _actionsToPerform.clear(); } // main loop @@ -944,12 +944,12 @@ void Scheduler::update(float dt) // Testing size is faster than locking / unlocking. // And almost never there will be functions scheduled to be called. - if (!_functionsToPerform.empty()) + if (!_actionsToPerform.empty()) { _performMutex.lock(); // fixed #4123: Save the callback functions, they must be invoked after '_performMutex.unlock()', otherwise if // new functions are added in callback, it will cause thread deadlock. - auto temp = std::move(_functionsToPerform); + auto temp = std::move(_actionsToPerform); _performMutex.unlock(); for (const auto& function : temp) diff --git a/core/base/CCScheduler.h b/core/base/CCScheduler.h index a79050fc63..13736e06c6 100644 --- a/core/base/CCScheduler.h +++ b/core/base/CCScheduler.h @@ -449,7 +449,12 @@ public: @since v3.0 @js NA */ - void performFunctionInCocosThread(std::function function); + void runOnAxmolThread(std::function action); + + AX_DEPRECATED_ATTRIBUTE void performFunctionInCocosThread(std::function action) + { + runOnAxmolThread(std::move(action)); + } /** * Remove all pending functions queued to be performed with Scheduler::performFunctionInCocosThread @@ -458,7 +463,8 @@ public: * @since v3.14 * @js NA */ - void removeAllFunctionsToBePerformedInCocosThread(); + void removeAllPendingActions(); + AX_DEPRECATED_ATTRIBUTE void removeAllFunctionsToBePerformedInCocosThread() { removeAllPendingActions(); } protected: /** Schedules the 'callback' function for a given target with a given priority. @@ -501,8 +507,8 @@ protected: Vector _scriptHandlerEntries; #endif - // Used for "perform Function" - std::vector> _functionsToPerform; + // Used for "perform action" + std::vector> _actionsToPerform; std::mutex _performMutex; };