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:
Arnold
2019-04-25 18:43:01 +08:00
committed by Jare Guo
parent 57554f4ed9
commit d88d4ffead
12 changed files with 85 additions and 49 deletions
+10 -6
View File
@@ -115,9 +115,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();
}
@@ -143,9 +143,9 @@ void HttpClient::networkThreadAlone(HttpRequest* request, HttpResponse* response
processResponse(response, responseMessage);
_schedulerMutex.lock();
if (nullptr != _scheduler)
if (auto sche = _scheduler.lock())
{
_scheduler->performFunctionInCocosThread([this, response, request]{
sche->performFunctionInCocosThread([this, response, request]{
const ccHttpRequestCallback& callback = request->getResponseCallback();
if (callback != nullptr)
@@ -356,9 +356,13 @@ 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();
thiz->_requestQueueMutex.lock();