mirror of https://github.com/axmolengine/axmol.git
Renaming performFunctionInCocosThread to runOnAxmolThread
This commit is contained in:
parent
0f97e3fa3a
commit
319aaf3a49
|
@ -264,7 +264,7 @@ Scheduler::Scheduler()
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// I don't expect to have more than 30 functions to all per frame
|
// I don't expect to have more than 30 functions to all per frame
|
||||||
_functionsToPerform.reserve(30);
|
_actionsToPerform.reserve(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
Scheduler::~Scheduler()
|
Scheduler::~Scheduler()
|
||||||
|
@ -812,16 +812,16 @@ void Scheduler::resumeTargets(const std::set<void*>& targetsToResume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::performFunctionInCocosThread(std::function<void()> function)
|
void Scheduler::runOnAxmolThread(std::function<void()> action)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_performMutex);
|
std::lock_guard<std::mutex> lock(_performMutex);
|
||||||
_functionsToPerform.emplace_back(std::move(function));
|
_actionsToPerform.emplace_back(std::move(action));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::removeAllFunctionsToBePerformedInCocosThread()
|
void Scheduler::removeAllPendingActions()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(_performMutex);
|
std::unique_lock<std::mutex> lock(_performMutex);
|
||||||
_functionsToPerform.clear();
|
_actionsToPerform.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// main loop
|
// main loop
|
||||||
|
@ -944,12 +944,12 @@ void Scheduler::update(float dt)
|
||||||
|
|
||||||
// Testing size is faster than locking / unlocking.
|
// Testing size is faster than locking / unlocking.
|
||||||
// And almost never there will be functions scheduled to be called.
|
// And almost never there will be functions scheduled to be called.
|
||||||
if (!_functionsToPerform.empty())
|
if (!_actionsToPerform.empty())
|
||||||
{
|
{
|
||||||
_performMutex.lock();
|
_performMutex.lock();
|
||||||
// fixed #4123: Save the callback functions, they must be invoked after '_performMutex.unlock()', otherwise if
|
// 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.
|
// new functions are added in callback, it will cause thread deadlock.
|
||||||
auto temp = std::move(_functionsToPerform);
|
auto temp = std::move(_actionsToPerform);
|
||||||
_performMutex.unlock();
|
_performMutex.unlock();
|
||||||
|
|
||||||
for (const auto& function : temp)
|
for (const auto& function : temp)
|
||||||
|
|
|
@ -449,7 +449,12 @@ public:
|
||||||
@since v3.0
|
@since v3.0
|
||||||
@js NA
|
@js NA
|
||||||
*/
|
*/
|
||||||
void performFunctionInCocosThread(std::function<void()> function);
|
void runOnAxmolThread(std::function<void()> action);
|
||||||
|
|
||||||
|
AX_DEPRECATED_ATTRIBUTE void performFunctionInCocosThread(std::function<void()> action)
|
||||||
|
{
|
||||||
|
runOnAxmolThread(std::move(action));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all pending functions queued to be performed with Scheduler::performFunctionInCocosThread
|
* Remove all pending functions queued to be performed with Scheduler::performFunctionInCocosThread
|
||||||
|
@ -458,7 +463,8 @@ public:
|
||||||
* @since v3.14
|
* @since v3.14
|
||||||
* @js NA
|
* @js NA
|
||||||
*/
|
*/
|
||||||
void removeAllFunctionsToBePerformedInCocosThread();
|
void removeAllPendingActions();
|
||||||
|
AX_DEPRECATED_ATTRIBUTE void removeAllFunctionsToBePerformedInCocosThread() { removeAllPendingActions(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Schedules the 'callback' function for a given target with a given priority.
|
/** Schedules the 'callback' function for a given target with a given priority.
|
||||||
|
@ -501,8 +507,8 @@ protected:
|
||||||
Vector<SchedulerScriptHandlerEntry*> _scriptHandlerEntries;
|
Vector<SchedulerScriptHandlerEntry*> _scriptHandlerEntries;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Used for "perform Function"
|
// Used for "perform action"
|
||||||
std::vector<std::function<void()>> _functionsToPerform;
|
std::vector<std::function<void()>> _actionsToPerform;
|
||||||
std::mutex _performMutex;
|
std::mutex _performMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue