fix:Add lock protection to Invoke rFactory destructor

Signed-off-by: chenchong_666 <chenchong57@huawei.com>
This commit is contained in:
chenchong_666 2024-08-08 16:22:03 +08:00
parent e7a498cdba
commit 1ea804d951
2 changed files with 3 additions and 2 deletions

View File

@ -37,7 +37,7 @@ private:
InvokerFactory(const InvokerFactory &) = delete;
InvokerFactory();
~InvokerFactory();
static bool isAvailable_;
static std::atomic<bool> isAvailable_;
std::mutex factoryMutex_;
std::unordered_map<int, InvokerCreator> creators_;
};

View File

@ -27,12 +27,13 @@ namespace OHOS {
#ifdef CONFIG_IPC_SINGLE
namespace IPC_SINGLE {
#endif
bool InvokerFactory::isAvailable_ = true;
std::atomic<bool> InvokerFactory::isAvailable_ = true;
InvokerFactory::InvokerFactory() {}
InvokerFactory::~InvokerFactory()
{
std::lock_guard<std::mutex> lockGuard(factoryMutex_);
isAvailable_ = false;
creators_.clear();
}