[Common] Changed method of deviced listener implementation 15/272315/2
authorPiotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Mon, 14 Mar 2022 10:46:24 +0000 (11:46 +0100)
committerPiotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Mon, 14 Mar 2022 12:20:40 +0000 (13:20 +0100)
To prevent crash in multithreaded model of wrt-services, there is a need
to use device_changed_callback_ as a thread local variable.

[Verification] Code compiles without errors.

Change-Id: Ifba2cef597e6244ab9c071b10c870b942b500946

src/common/filesystem/filesystem_provider_deviced.cc
src/common/filesystem/filesystem_provider_deviced.h

index 60bc109..9bfb5ea 100644 (file)
@@ -54,6 +54,7 @@ bool isExternalStorageSupported() {
   return true;
 }
 
+thread_local common::DeviceChangeStateFun device_changed_callback_;
 }  // namespace
 
 namespace common {
@@ -122,7 +123,6 @@ FilesystemProviderDeviced::~FilesystemProviderDeviced() {
 FilesystemProviderDeviced::FilesystemProviderDeviced()
     : dbus_(nullptr),
       proxy_(nullptr),
-      device_changed_callback_(nullptr),
       block_signal_subscribe_id_(0),
       virtual_roots_provider_(FilesystemProviderStorage::Create()),
       is_initialized_(false) {
@@ -190,7 +190,7 @@ void FilesystemProviderDeviced::RegisterDeviceChangeState(DeviceChangeStateFun _
     return;
   }
 
-  if (device_changed_callback_ == nullptr) {
+  if (0 == block_signal_subscribe_id_) {
     LoggerD("Registering dbus signal subscription");
     block_signal_subscribe_id_ = g_dbus_connection_signal_subscribe(
         dbus_, nullptr, kBlockManagerIface, kDeviceChangedMethod, nullptr, nullptr,
index 65746b8..4491c12 100644 (file)
@@ -60,7 +60,6 @@ class FilesystemProviderDeviced : public IFilesystemProvider {
   GDBusConnection* dbus_;
   GDBusProxy* proxy_;
 
-  DeviceChangeStateFun device_changed_callback_;
   guint block_signal_subscribe_id_;
   std::map<std::string, StorageState> previous_device_state_map_;
   FilesystemProviderRef virtual_roots_provider_;