From: Arkadiusz Pietraszek Date: Wed, 20 Jun 2018 08:58:57 +0000 (+0200) Subject: [Filesystem] Fix for thread that may outlive object it reffers to X-Git-Tag: submit/tizen/20180816.094841~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6d9518802013e69822398698752c99a6673d6100;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] Fix for thread that may outlive object it reffers to [Verification] tizen.filesystem methods work properly. Worker and insstance destructors work properly. Change-Id: I5724bd798c868aaba23e9f4e5c5f4ba0b13d2faf Signed-off-by: Arkadiusz Pietraszek --- diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index be8e802a..52f5948c 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -145,6 +145,12 @@ FilesystemInstance::Worker::Worker() } FilesystemInstance::Worker::~Worker() { + if(!exit && thread.joinable()) { + stop(); + } +} + +void FilesystemInstance::Worker::stop() { { // use memory barrier for exit flag (could be std::atomic_flag, but we use lock instead) std::lock_guard lck{jobs_mtx}; @@ -228,6 +234,7 @@ FilesystemInstance::FilesystemInstance() { FilesystemInstance::~FilesystemInstance() { ScopeLogger(); + worker.stop(); FilesystemManager::GetInstance().StopListening(); FilesystemManager::GetInstance().RemoveListener(); } diff --git a/src/filesystem/filesystem_instance.h b/src/filesystem/filesystem_instance.h index 37214966..617fab3a 100644 --- a/src/filesystem/filesystem_instance.h +++ b/src/filesystem/filesystem_instance.h @@ -80,6 +80,7 @@ class FilesystemInstance : public common::ParsedInstance, FilesystemStateChangeL void main(void); public: + void stop(); Worker(); ~Worker();