diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 64efe41..f5bca60 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -19,6 +19,7 @@ */ #include +#include #include #include #include @@ -205,15 +206,13 @@ static int s3fs_removexattr(const char* path, const char* name); class MpStatFlag { private: - mutable pthread_mutex_t flag_lock; - bool is_lock_init = false; - bool has_mp_stat = false; + std::atomic has_mp_stat; public: - MpStatFlag(); + MpStatFlag() = default; MpStatFlag(const MpStatFlag&) = delete; MpStatFlag(MpStatFlag&&) = delete; - ~MpStatFlag(); + ~MpStatFlag() = default; MpStatFlag& operator=(const MpStatFlag&) = delete; MpStatFlag& operator=(MpStatFlag&&) = delete; @@ -221,46 +220,14 @@ class MpStatFlag bool Set(bool flag); }; -MpStatFlag::MpStatFlag() -{ - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); -#if S3FS_PTHREAD_ERRORCHECK - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); -#endif - - int result; - if(0 != (result = pthread_mutex_init(&flag_lock, &attr))){ - S3FS_PRN_CRIT("failed to init flag_lock: %d", result); - abort(); - } - is_lock_init = true; -} - -MpStatFlag::~MpStatFlag() -{ - if(is_lock_init){ - int result; - if(0 != (result = pthread_mutex_destroy(&flag_lock))){ - S3FS_PRN_CRIT("failed to destroy flag_lock: %d", result); - abort(); - } - is_lock_init = false; - } -} - bool MpStatFlag::Get() { - AutoLock auto_lock(&flag_lock); return has_mp_stat; } bool MpStatFlag::Set(bool flag) { - AutoLock auto_lock(&flag_lock); - bool old = has_mp_stat; - has_mp_stat = flag; - return old; + return has_mp_stat.exchange(flag); } // whether the stat information file for mount point exists diff --git a/src/threadpoolman.cpp b/src/threadpoolman.cpp index 3bc2e2e..682529d 100644 --- a/src/threadpoolman.cpp +++ b/src/threadpoolman.cpp @@ -117,7 +117,7 @@ void* ThreadPoolMan::Worker(void* arg) //------------------------------------------------ // ThreadPoolMan methods //------------------------------------------------ -ThreadPoolMan::ThreadPoolMan(int count) : is_exit(false), thpoolman_sem(0), is_lock_init(false), is_exit_flag_init(false) +ThreadPoolMan::ThreadPoolMan(int count) : is_exit(false), thpoolman_sem(0), is_lock_init(false) { if(count < 1){ S3FS_PRN_CRIT("Failed to creating singleton for Thread Manager, because thread count(%d) is under 1.", count); @@ -141,12 +141,6 @@ ThreadPoolMan::ThreadPoolMan(int count) : is_exit(false), thpoolman_sem(0), is_l } is_lock_init = true; - if(0 != (result = pthread_mutex_init(&thread_exit_flag_lock, &attr))){ - S3FS_PRN_CRIT("failed to init thread_exit_flag_lock: %d", result); - abort(); - } - is_exit_flag_init = true; - // create threads if(!StartThreads(count)){ S3FS_PRN_ERR("Failed starting threads at initializing."); @@ -166,25 +160,15 @@ ThreadPoolMan::~ThreadPoolMan() } is_lock_init = false; } - if(is_exit_flag_init ){ - int result; - if(0 != (result = pthread_mutex_destroy(&thread_exit_flag_lock))){ - S3FS_PRN_CRIT("failed to destroy thread_exit_flag_lock: %d", result); - abort(); - } - is_exit_flag_init = false; - } } bool ThreadPoolMan::IsExit() const { - AutoLock auto_lock(&thread_exit_flag_lock); return is_exit; } void ThreadPoolMan::SetExitFlag(bool exit_flag) { - AutoLock auto_lock(&thread_exit_flag_lock); is_exit = exit_flag; } diff --git a/src/threadpoolman.h b/src/threadpoolman.h index 0a9769b..675f374 100644 --- a/src/threadpoolman.h +++ b/src/threadpoolman.h @@ -21,6 +21,7 @@ #ifndef S3FS_THREADPOOLMAN_H_ #define S3FS_THREADPOOLMAN_H_ +#include #include #include #include @@ -64,7 +65,7 @@ class ThreadPoolMan private: static ThreadPoolMan* singleton; - bool is_exit; + std::atomic is_exit; Semaphore thpoolman_sem; bool is_lock_init; @@ -73,9 +74,6 @@ class ThreadPoolMan thpoolman_params_t instruction_list; - bool is_exit_flag_init; - mutable pthread_mutex_t thread_exit_flag_lock; - private: static void* Worker(void* arg);