mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Use smart pointers to hold references of global Application::_scheduler (#1732)
* use std::weak_ptr * revert build/libcocos2d.vcxproj * fix mac & ios & android * declare variable in if block * revert build/libcocos2d.vcxproj
This commit is contained in:
@@ -838,9 +838,9 @@ void HttpClient::networkThread()
|
||||
_responseQueueMutex.unlock();
|
||||
|
||||
_schedulerMutex.lock();
|
||||
if (nullptr != _scheduler)
|
||||
if (auto sche = _scheduler.lock())
|
||||
{
|
||||
_scheduler->performFunctionInCocosThread(CC_CALLBACK_0(HttpClient::dispatchResponseCallbacks, this));
|
||||
sche->performFunctionInCocosThread(CC_CALLBACK_0(HttpClient::dispatchResponseCallbacks, this));
|
||||
}
|
||||
_schedulerMutex.unlock();
|
||||
}
|
||||
@@ -866,9 +866,9 @@ void HttpClient::networkThreadAlone(HttpRequest* request, HttpResponse* response
|
||||
processResponse(response, responseMessage);
|
||||
|
||||
_schedulerMutex.lock();
|
||||
if (_scheduler != nullptr)
|
||||
if (auto sche = _scheduler.lock())
|
||||
{
|
||||
_scheduler->performFunctionInCocosThread([this, response, request]{
|
||||
sche->performFunctionInCocosThread([this, response, request]{
|
||||
const ccHttpRequestCallback& callback = request->getResponseCallback();
|
||||
|
||||
if (callback != nullptr)
|
||||
@@ -909,10 +909,12 @@ void HttpClient::destroyInstance()
|
||||
auto thiz = _httpClient;
|
||||
_httpClient = nullptr;
|
||||
|
||||
thiz->_scheduler->unscheduleAllForTarget(thiz);
|
||||
|
||||
if(auto sche = thiz->_scheduler.lock()) {
|
||||
sche->unscheduleAllForTarget(thiz);
|
||||
}
|
||||
thiz->_schedulerMutex.lock();
|
||||
thiz->_scheduler = nullptr;
|
||||
thiz->_scheduler.reset();
|
||||
thiz->_schedulerMutex.unlock();
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user