diff --git a/ipc/native/src/mock/include/invoker_factory.h b/ipc/native/src/mock/include/invoker_factory.h index acfc2485..feca5265 100644 --- a/ipc/native/src/mock/include/invoker_factory.h +++ b/ipc/native/src/mock/include/invoker_factory.h @@ -37,7 +37,7 @@ private: InvokerFactory(const InvokerFactory &) = delete; InvokerFactory(); ~InvokerFactory(); - static bool isAvailable_; + static std::atomic isAvailable_; std::mutex factoryMutex_; std::unordered_map creators_; }; diff --git a/ipc/native/src/mock/source/invoker_factory.cpp b/ipc/native/src/mock/source/invoker_factory.cpp index 5b2946b3..9e2d2aeb 100644 --- a/ipc/native/src/mock/source/invoker_factory.cpp +++ b/ipc/native/src/mock/source/invoker_factory.cpp @@ -27,12 +27,13 @@ namespace OHOS { #ifdef CONFIG_IPC_SINGLE namespace IPC_SINGLE { #endif -bool InvokerFactory::isAvailable_ = true; +std::atomic InvokerFactory::isAvailable_ = true; InvokerFactory::InvokerFactory() {} InvokerFactory::~InvokerFactory() { + std::lock_guard lockGuard(factoryMutex_); isAvailable_ = false; creators_.clear(); }