Changing scheduling jobs to the main loop/worker 92/187592/4
authorSzymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Fri, 24 Aug 2018 10:15:08 +0000 (12:15 +0200)
committerSzymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Tue, 25 Sep 2018 08:54:39 +0000 (10:54 +0200)
+ 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 <s.jastrzebsk@partner.samsung.com>
src/callhistory/callhistory.cc
src/networkbearerselection/networkbearerselection_instance.cc
src/networkbearerselection/networkbearerselection_manager.cc
src/preference/preference_manager.cc
src/secureelement/secureelement_instance.cc
src/systemsetting/systemsetting_instance.cc
src/widgetservice/widgetservice_instance.cc

index 2f972a70cf25b716fccab309a4a4a680e2b390f8..9b610577216d201794e55cbda5d14f88a9ff4203 100644 (file)
@@ -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) {
index ea33972204852a5966829218b7e591c64e1bb4ed..a88cecc03a92789c1695fbdb4c1467ad918a0878 100644 (file)
@@ -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);
 }
 
index b6206f468d62fc0b36e14db292aa1143864fbd8c..b592946df785d4f47350c37363b8eff647fd625e 100644 (file)
@@ -17,6 +17,7 @@
 #include "networkbearerselection_manager.h"
 #include "common/logger.h"
 #include "common/scope_exit.h"
+#include "common/task-queue.h"
 
 #include <arpa/inet.h>
 #include <netdb.h>
@@ -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,
index ecd9665ee73c2711c3d5de268db1cf3da320e4e3..95c82eecd32dd7f1b77c765fa734e69f6eea3c39 100644 (file)
@@ -19,6 +19,7 @@
 #include <thread>
 
 #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();
 }
index eccb69254c82161cef45d243a4bb6a61744df973..75efd10266037bbfdc41c20ae58b2f0fe5b0a5e9 100644 (file)
@@ -20,6 +20,7 @@
 #include <thread>
 
 #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();
 }
index e791bc2c82ac8f01e812e602e6f5ab25d9ef2a68..55c58af57a310987381a2780981eb0ca29e320ff 100644 (file)
@@ -161,7 +161,10 @@ void SystemSettingInstance::setProperty(const picojson::value& args, picojson::o
 
   auto data = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
 
-  TaskQueue::GetInstance().Async<picojson::value>(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<picojson::value>(get, data);
 }
 
 PlatformResult SystemSettingInstance::setPlatformPropertyValue(const std::string& settingType,
index bbd61c018b20b6f687d6bbb299255b299a944c92..a6b6df2b2d90ef3487489ce46cb3f40ada3396b2 100644 (file)
@@ -24,6 +24,7 @@
 #include <widget_service.h>
 
 #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();
 }