mirror of
https://gitee.com/openharmony/communication_ipc
synced 2024-11-23 07:50:24 +00:00
!850 非foundation进程使用numExecuting_导致死锁
Merge pull request !850 from hhl/master
This commit is contained in:
commit
8c9d5f052d
@ -33,6 +33,8 @@
|
||||
OHOS::InvokerFactory*;
|
||||
OHOS::IPCDfx*;
|
||||
OHOS::IPCSkeleton*;
|
||||
OHOS::IPCProcessSkeleton::LockForNumExecuting;
|
||||
OHOS::IPCProcessSkeleton::UnlockForNumExecuting;
|
||||
OHOS::IRemoteObject*;
|
||||
OHOS::BinderInvoker*;
|
||||
OHOS::BrokerRegistration*;
|
||||
|
@ -24,6 +24,8 @@
|
||||
OHOS::BrokerRegistration::Unregister*;
|
||||
OHOS::BrokerRegistration::NewInstance*;
|
||||
OHOS::IPCSkeleton*;
|
||||
OHOS::IPC_SINGLE::IPCProcessSkeleton::LockForNumExecuting;
|
||||
OHOS::IPC_SINGLE::IPCProcessSkeleton::UnlockForNumExecuting;
|
||||
OHOS::IPC_SINGLE::IPCThreadSkeleton*;
|
||||
OHOS::IRemoteObject*;
|
||||
"OHOS::IPC_SINGLE::BinderInvoker::BinderInvoker()";
|
||||
|
@ -103,6 +103,8 @@ public:
|
||||
sptr<IRemoteObject> GetRegistryObject();
|
||||
bool SetRegistryObject(sptr<IRemoteObject> &object);
|
||||
void BlockUntilThreadAvailable();
|
||||
void LockForNumExecuting();
|
||||
void UnlockForNumExecuting();
|
||||
|
||||
#ifndef CONFIG_IPC_SINGLE
|
||||
bool AttachRawData(uint32_t fd, std::shared_ptr<InvokerRawData> rawData);
|
||||
@ -188,17 +190,18 @@ public:
|
||||
static constexpr uint32_t DBINDER_HANDLE_BASE = 100000 * DBINDER_HANDLE_MAGIC;
|
||||
static constexpr uint32_t DBINDER_HANDLE_COUNT = 100000;
|
||||
static constexpr uint32_t DBINDER_HANDLE_RANG = 100;
|
||||
static constexpr int32_t FOUNDATION_UID = 5523;
|
||||
static constexpr int ENCRYPT_LENGTH = 4;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable cv_;
|
||||
int numExecuting_ = 0;
|
||||
int numWaitingForThreads_ = 0;
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(IPCProcessSkeleton);
|
||||
IPCProcessSkeleton();
|
||||
static IPCProcessSkeleton *instance_;
|
||||
static std::mutex procMutex_;
|
||||
std::shared_mutex rawDataMutex_;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable cv_;
|
||||
int numExecuting_ = 0;
|
||||
int numWaitingForThreads_ = 0;
|
||||
|
||||
std::map<uint32_t, std::shared_ptr<InvokerRawData>> rawData_;
|
||||
IPCWorkThreadPool *threadPool_ = nullptr;
|
||||
|
@ -321,6 +321,27 @@ void IPCProcessSkeleton::BlockUntilThreadAvailable()
|
||||
numWaitingForThreads_--;
|
||||
}
|
||||
|
||||
void IPCProcessSkeleton::LockForNumExecuting()
|
||||
{
|
||||
if (getuid() != FOUNDATION_UID) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lockGuard(mutex_);
|
||||
numExecuting_++;
|
||||
}
|
||||
|
||||
void IPCProcessSkeleton::UnlockForNumExecuting()
|
||||
{
|
||||
if (getuid() != FOUNDATION_UID) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lockGuard(mutex_);
|
||||
numExecuting_--;
|
||||
if (numWaitingForThreads_ > 0) {
|
||||
cv_.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef CONFIG_IPC_SINGLE
|
||||
sptr<IRemoteObject> IPCProcessSkeleton::GetSAMgrObject()
|
||||
{
|
||||
|
@ -346,17 +346,12 @@ void BinderInvoker::StartWorkLoop()
|
||||
}
|
||||
uint32_t cmd = input_.ReadUint32();
|
||||
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(current->mutex_);
|
||||
current->numExecuting_++;
|
||||
if (current != nullptr) {
|
||||
current->LockForNumExecuting();
|
||||
}
|
||||
int userError = HandleCommands(cmd);
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(current->mutex_);
|
||||
current->numExecuting_--;
|
||||
if (current->numWaitingForThreads_ > 0) {
|
||||
current->cv_.notify_all();
|
||||
}
|
||||
if (current != nullptr) {
|
||||
current->UnlockForNumExecuting();
|
||||
}
|
||||
if ((userError == -ERR_TIMED_OUT || userError == IPC_INVOKER_INVALID_DATA_ERR) && !isMainWorkThread) {
|
||||
ZLOGW(LABEL, "exit, userError:%{public}d", userError);
|
||||
|
Loading…
Reference in New Issue
Block a user