From 6d9518802013e69822398698752c99a6673d6100 Mon Sep 17 00:00:00 2001 From: Arkadiusz Pietraszek Date: Wed, 20 Jun 2018 10:58:57 +0200 Subject: [PATCH] [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 --- src/filesystem/filesystem_instance.cc | 7 +++++++ src/filesystem/filesystem_instance.h | 1 + 2 files changed, 8 insertions(+) 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(); -- 2.34.1