未验证 提交 d5a3f99b 编写于 作者: O openharmony_ci 提交者: Gitee

!734 binder full enhances

Merge pull request !734 from Carmack/master
......@@ -163,5 +163,18 @@ public:
*/
static bool SetCallingIdentity(std::string &identity);
};
class IPCDfx {
public:
IPCDfx() = default;
~IPCDfx() = default;
/**
* @brief Block until idle ipc thread available.CAUTION: DO NOT USE IT ELSEWHERE EXPECT HICOLLIE!
* @return void
* @since 9
*/
static void BlockUntilThreadAvailable();
};
} // namespace OHOS
#endif // OHOS_IPC_IPC_SKELETON_H
......@@ -23,6 +23,7 @@
OHOS::BrokerRegistration::Register*;
OHOS::BrokerRegistration::Unregister*;
OHOS::BrokerRegistration::NewInstance*;
OHOS::IPCDfx*;
OHOS::IPCSkeleton*;
OHOS::IRemoteObject*;
"OHOS::MessageParcel::MessageParcel()";
......@@ -92,4 +93,4 @@
};
local:
*;
};
\ No newline at end of file
};
......@@ -102,6 +102,7 @@ public:
sptr<IRemoteObject> GetRegistryObject();
bool SetRegistryObject(sptr<IRemoteObject> &object);
void BlockUntilThreadAvailable();
#ifndef CONFIG_IPC_SINGLE
bool AttachRawData(uint32_t fd, std::shared_ptr<InvokerRawData> rawData);
......
......@@ -16,6 +16,7 @@
#ifndef OHOS_IPC_IPC_WORK_THREAD_POOL_H
#define OHOS_IPC_IPC_WORK_THREAD_POOL_H
#include <condition_variable>
#include <functional>
#include <thread>
#include <map>
......@@ -55,6 +56,7 @@ public:
void UpdateMaxThreadNum(int maxThreadNum);
int GetSocketIdleThreadNum() const;
int GetSocketTotalThreadNum() const;
void BlockUntilThreadAvailable();
private:
static constexpr int PROTO_NUM = 2;
......@@ -65,6 +67,8 @@ private:
int idleThreadNum_;
int idleSocketThreadNum_;
std::mutex mutex_;
int numWaitingForThreads_;
std::condition_variable cv_;
static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCWorkThreadPool" };
};
#ifdef CONFIG_IPC_SINGLE
......
......@@ -307,6 +307,13 @@ sptr<IRemoteObject> IPCProcessSkeleton::QueryObject(const std::u16string &descri
return current->QueryObject(descriptor);
}
void IPCProcessSkeleton::BlockUntilThreadAvailable()
{
if (threadPool_ != nullptr) {
threadPool_->BlockUntilThreadAvailable();
}
}
#ifndef CONFIG_IPC_SINGLE
sptr<IRemoteObject> IPCProcessSkeleton::GetSAMgrObject()
{
......
......@@ -209,4 +209,12 @@ bool IPCSkeleton::SetCallingIdentity(std::string &identity)
return true;
}
void IPCDfx::BlockUntilThreadAvailable()
{
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
if (current != nullptr) {
current->BlockUntilThreadAvailable();
}
}
} // namespace OHOS
......@@ -30,7 +30,8 @@ IPCWorkThreadPool::IPCWorkThreadPool(int maxThreadNum)
: threadSequence_(0),
maxThreadNum_(maxThreadNum + maxThreadNum),
idleThreadNum_(maxThreadNum),
idleSocketThreadNum_(maxThreadNum)
idleSocketThreadNum_(maxThreadNum),
numWaitingForThreads_(0)
{}
IPCWorkThreadPool::~IPCWorkThreadPool()
......@@ -102,6 +103,9 @@ bool IPCWorkThreadPool::RemoveThread(const std::string &threadName)
}
if (workThread->proto_ == IRemoteObject::IF_PROT_DEFAULT) {
idleThreadNum_++;
if (numWaitingForThreads_ > 0) {
cv_.notify_all();
}
} else if (workThread->proto_ == IRemoteObject::IF_PROT_DATABUS) {
idleSocketThreadNum_++;
}
......@@ -142,6 +146,16 @@ void IPCWorkThreadPool::UpdateMaxThreadNum(int maxThreadNum)
idleThreadNum_ += diff / PROTO_NUM;
idleSocketThreadNum_ += diff / PROTO_NUM;
}
void IPCWorkThreadPool::BlockUntilThreadAvailable()
{
std::unique_lock<std::mutex> lock(mutex_);
numWaitingForThreads_++;
while (idleThreadNum_ <= 0) {
cv_.wait(lock);
}
numWaitingForThreads_--;
}
#ifdef CONFIG_IPC_SINGLE
} // namespace IPC_SINGLE
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册