!1136 【IPC/RPC】BrokerDelegator构造和析构中添加锁保护

Merge pull request !1136 from chenchong_666/master
This commit is contained in:
openharmony_ci 2024-05-27 02:30:38 +00:00 committed by Gitee
commit c2d9edc00e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -131,10 +131,12 @@ private:
BrokerDelegator(BrokerDelegator &&) = delete;
BrokerDelegator &operator = (const BrokerDelegator &) = delete;
BrokerDelegator &operator = (BrokerDelegator &&) = delete;
std::mutex regMutex_;
};
template <typename T> BrokerDelegator<T>::BrokerDelegator()
{
std::lock_guard<std::mutex> lockGuard(regMutex_);
const std::u16string descriptor = T::GetDescriptor();
BrokerRegistration &registration = BrokerRegistration::Get();
if (registration.Register(descriptor, BrokerCreator<T>(), this)) {
@ -144,6 +146,7 @@ template <typename T> BrokerDelegator<T>::BrokerDelegator()
template <typename T> BrokerDelegator<T>::~BrokerDelegator()
{
std::lock_guard<std::mutex> lockGuard(regMutex_);
if (!isSoUnloaded && !descriptor_.empty()) {
BrokerRegistration &registration = BrokerRegistration::Get();
registration.Unregister(descriptor_);