From: Szymon Jastrzebski Date: Fri, 24 Aug 2018 10:15:08 +0000 (+0200) Subject: Changing scheduling jobs to the main loop/worker X-Git-Tag: submit/tizen/20181126.112620~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec5c84bc71ae37c617a98d4dc93b7ffa14b023ea;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git Changing scheduling jobs to the main loop/worker + Creating stand-alone threads should be only exceptional, thus the occurrences have been replaced by calling TaskQueue::Async. [Verification] Callhistory, NBS, Preference, SE, SS, Widget TCT 100% pass rate Change-Id: Ibf7493d04c2cd48221d4a4f9f708722e61ee1459 Signed-off-by: Szymon Jastrzebski --- diff --git a/src/callhistory/callhistory.cc b/src/callhistory/callhistory.cc index 2f972a70..9b610577 100644 --- a/src/callhistory/callhistory.cc +++ b/src/callhistory/callhistory.cc @@ -305,11 +305,11 @@ void CallHistory::LoadPhoneNumbers(const picojson::object& args, CallHistory* ca void CallHistory::find(const picojson::object& args) { ScopeLogger(); - std::thread([args, this]() { - ScopeLogger("Entered into asynchronus function, std::thread's argument"); + common::TaskQueue::GetInstance().Async([args, this]() { + ScopeLogger("Entered into asynchronus function"); LoadPhoneNumbers(args, this); FindThread(args, this); - }).detach(); + }); } PlatformResult CallHistory::remove(const picojson::object& args) { diff --git a/src/networkbearerselection/networkbearerselection_instance.cc b/src/networkbearerselection/networkbearerselection_instance.cc index ea339722..a88cecc0 100644 --- a/src/networkbearerselection/networkbearerselection_instance.cc +++ b/src/networkbearerselection/networkbearerselection_instance.cc @@ -110,7 +110,13 @@ void NetworkBearerSelectionInstance::NetworkBearerSelectionRequestRouteToHost( NetworkBearerSelectionManager::GetInstance()->requestRouteToHost(domain_name, response); }; - common::TaskQueue::GetInstance().Async(request); + // The RequestRouteToHost has to be executed in the main thread because of Native API + // implementation. The Web API implementation of NBSManager class has a global connection_h + // handle, which is used in every Request() method. + // However, the Native implementation uses std::thread_local-like variables, thus + // an execution of RequestRouteToHost() in thread different than main thread results in returning + // an error from C-API. + common::TaskQueue::GetInstance().ScheduleWorkInMainThread(request); ReportSuccess(out); } @@ -155,7 +161,13 @@ void NetworkBearerSelectionInstance::NetworkBearerSelectionReleaseRouteToHost( NetworkBearerSelectionManager::GetInstance()->releaseRouteToHost(domain_name, response); }; - common::TaskQueue::GetInstance().Async(release); + // The ReleaseRouteToHost has to be executed in the main thread because of Native API + // implementation. The Web API implementation of NBSManager class has a global connection_h + // handle, which is used in every Request() method. + // However, the Native implementation uses std::thread_local-like variables, thus + // an execution of RequestRouteToHost/ReleaseRouteToHost() in thread different than main thread + // results in returning an error from C-API. + common::TaskQueue::GetInstance().ScheduleWorkInMainThread(release); ReportSuccess(out); } diff --git a/src/networkbearerselection/networkbearerselection_manager.cc b/src/networkbearerselection/networkbearerselection_manager.cc index b6206f46..b592946d 100644 --- a/src/networkbearerselection/networkbearerselection_manager.cc +++ b/src/networkbearerselection/networkbearerselection_manager.cc @@ -17,6 +17,7 @@ #include "networkbearerselection_manager.h" #include "common/logger.h" #include "common/scope_exit.h" +#include "common/task-queue.h" #include #include @@ -183,7 +184,8 @@ void NetworkBearerSelectionManager::callResultCallback(const ReplyCallback& repl const PlatformResult result) { ScopeLogger(); - std::thread(reply, result).detach(); + auto reply_wrapper = [=] { reply(result); }; + common::TaskQueue::GetInstance().Async(reply_wrapper); } void NetworkBearerSelectionManager::requestRouteToHost(const std::string& domain_name, diff --git a/src/preference/preference_manager.cc b/src/preference/preference_manager.cc index ecd9665e..95c82eec 100644 --- a/src/preference/preference_manager.cc +++ b/src/preference/preference_manager.cc @@ -19,6 +19,7 @@ #include #include "common/logger.h" +#include "common/task-queue.h" #include "common/tools.h" #include "preference/preference_instance.h" #include "preference/preference_manager.h" @@ -173,7 +174,9 @@ common::TizenResult PreferenceManager::GetAll(const common::PostCallback& callba callback(result, response); }; - std::thread(get_all, callback).detach(); + auto get_all_wrapper = [=] { get_all(callback); }; + + common::TaskQueue::GetInstance().Async(get_all_wrapper); return common::TizenSuccess(); } diff --git a/src/secureelement/secureelement_instance.cc b/src/secureelement/secureelement_instance.cc index eccb6925..75efd102 100644 --- a/src/secureelement/secureelement_instance.cc +++ b/src/secureelement/secureelement_instance.cc @@ -20,6 +20,7 @@ #include #include "common/scope_exit.h" +#include "common/task-queue.h" #include "common/tools.h" namespace extension { @@ -186,7 +187,7 @@ TizenResult SecureElementInstance::GetReaders(picojson::object const& args, this->Post(token, result); }; - std::thread(get_readers, token).detach(); + common::TaskQueue::GetInstance().Async(get_readers, token); return TizenSuccess(); } @@ -319,7 +320,7 @@ TizenResult SecureElementInstance::OpenSession(picojson::object const& args, this->Post(token, result); }; - std::thread(open_session, token).detach(); + common::TaskQueue::GetInstance().Async(open_session, token); return TizenSuccess(); } @@ -396,7 +397,7 @@ TizenResult SecureElementInstance::OpenBasicChannel(picojson::object const& args this->Post(token, result); }; - std::thread(open_basic_channel, token).detach(); + common::TaskQueue::GetInstance().Async(open_basic_channel, token); return TizenSuccess(); } @@ -441,7 +442,7 @@ TizenResult SecureElementInstance::OpenLogicalChannel(picojson::object const& ar this->Post(token, result); }; - std::thread(open_basic_logical, token).detach(); + common::TaskQueue::GetInstance().Async(open_basic_logical, token); return TizenSuccess(); } @@ -582,7 +583,7 @@ TizenResult SecureElementInstance::Transmit(picojson::object const& args, this->Post(token, result); }; - std::thread(transmit, token).detach(); + common::TaskQueue::GetInstance().Async(transmit, token); return TizenSuccess(); } diff --git a/src/systemsetting/systemsetting_instance.cc b/src/systemsetting/systemsetting_instance.cc index e791bc2c..55c58af5 100644 --- a/src/systemsetting/systemsetting_instance.cc +++ b/src/systemsetting/systemsetting_instance.cc @@ -161,7 +161,10 @@ void SystemSettingInstance::setProperty(const picojson::value& args, picojson::o auto data = std::shared_ptr(new picojson::value(picojson::object())); - TaskQueue::GetInstance().Async(get, data); + // Setting properties needs to be executed in main thread because of: + // "Internally, EFL uses data with TLSS(Thread Local Storage). + // Hence, there is no share data between Main thread and other thread." + TaskQueue::GetInstance().ScheduleWorkInMainThread(get, data); } PlatformResult SystemSettingInstance::setPlatformPropertyValue(const std::string& settingType, diff --git a/src/widgetservice/widgetservice_instance.cc b/src/widgetservice/widgetservice_instance.cc index bbd61c01..a6b6df2b 100644 --- a/src/widgetservice/widgetservice_instance.cc +++ b/src/widgetservice/widgetservice_instance.cc @@ -24,6 +24,7 @@ #include #include "common/scope_exit.h" +#include "common/task-queue.h" #include "common/tools.h" #include "widgetservice/widgetservice_utils.h" @@ -257,7 +258,7 @@ TizenResult WidgetServiceInstance::GetWidgets(const picojson::object& args, this->Post(token, result); }; - std::thread(get_widgets, token).detach(); + common::TaskQueue::GetInstance().Async(get_widgets, token); return TizenSuccess(); } @@ -361,7 +362,7 @@ TizenResult WidgetServiceInstance::GetInstances(picojson::object const& args, this->Post(token, result); }; - std::thread(get_instances, token).detach(); + common::TaskQueue::GetInstance().Async(get_instances, token); return TizenSuccess(); } @@ -459,7 +460,7 @@ TizenResult WidgetServiceInstance::GetVariants(picojson::object const& args, } }; - std::thread(get_variants, token).detach(); + common::TaskQueue::GetInstance().Async(get_variants, token); return TizenSuccess(); } @@ -643,7 +644,7 @@ TizenResult WidgetServiceInstance::GetContent(picojson::object const& args, this->Post(token, TizenSuccess{response}); }; - std::thread(get_content, token).detach(); + common::TaskQueue::GetInstance().Async(get_content, token); return TizenSuccess(); }