mirror of
https://gitee.com/openharmony/communication_ipc
synced 2024-12-04 14:18:48 +00:00
commit
b3735c7eba
@ -17,10 +17,7 @@ SUBSYSTEM_DIR = "//foundation/communication/ipc"
|
||||
IPC_CORE_ROOT = "$SUBSYSTEM_DIR/ipc/native"
|
||||
|
||||
config("libipc_core_private_config") {
|
||||
cflags_cc = [
|
||||
"-O2",
|
||||
"-fexceptions",
|
||||
]
|
||||
cflags_cc = [ "-O2" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("ipc_core") {
|
||||
|
@ -20,7 +20,6 @@ config("libipc_single_private_config") {
|
||||
cflags_cc = [
|
||||
"-DCONFIG_IPC_SINGLE",
|
||||
"-O2",
|
||||
"-fexceptions",
|
||||
]
|
||||
}
|
||||
ohos_shared_library("ipc_single") {
|
||||
|
@ -40,8 +40,6 @@ public:
|
||||
|
||||
~IPCWorkThread();
|
||||
|
||||
void ThreadHandler();
|
||||
|
||||
void Start(int policy, int proto, std::string threadName);
|
||||
|
||||
void StopWorkThread();
|
||||
@ -51,6 +49,7 @@ private:
|
||||
int policy_ = SPAWN_PASSIVE;
|
||||
std::thread thread_;
|
||||
const std::string threadName_;
|
||||
static void *ThreadHandler(void *args);
|
||||
static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCWorkThread" };
|
||||
};
|
||||
#ifdef CONFIG_IPC_SINGLE
|
||||
|
@ -76,15 +76,9 @@ bool IPCWorkThreadPool::SpawnThread(int policy, int proto)
|
||||
idleSocketThreadNum_--;
|
||||
DBINDER_LOGI("SpawnThread, now idleSocketThreadNum_ =%d", idleSocketThreadNum_);
|
||||
}
|
||||
|
||||
bool ret = true;
|
||||
try {
|
||||
newThread->Start(policy, proto, threadName);
|
||||
} catch (const std::exception& e) {
|
||||
DBINDER_LOGI("get exception:%{public}s", e.what());
|
||||
ret = false;
|
||||
}
|
||||
return ret;
|
||||
|
||||
newThread->Start(policy, proto, threadName);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ipc_workthread.h"
|
||||
#include <pthread.h>
|
||||
#include <sys/prctl.h>
|
||||
#include "ipc_debug.h"
|
||||
#include "ipc_process_skeleton.h"
|
||||
@ -38,13 +39,14 @@ IPCWorkThread::~IPCWorkThread()
|
||||
StopWorkThread();
|
||||
}
|
||||
|
||||
void IPCWorkThread::ThreadHandler()
|
||||
void *IPCWorkThread::ThreadHandler(void *args)
|
||||
{
|
||||
IRemoteInvoker *invoker = IPCThreadSkeleton::GetRemoteInvoker(proto_);
|
||||
DBINDER_LOGI("proto_=%d", proto_);
|
||||
IPCWorkThread *threadObj = (IPCWorkThread *)args;
|
||||
IRemoteInvoker *invoker = IPCThreadSkeleton::GetRemoteInvoker(threadObj->proto_);
|
||||
DBINDER_LOGI("proto_=%{public}d,policy_=%{public}d", threadObj->proto_, threadObj->policy_);
|
||||
|
||||
if (invoker != nullptr) {
|
||||
switch (policy_) {
|
||||
switch (threadObj->policy_) {
|
||||
case SPAWN_PASSIVE:
|
||||
invoker->JoinThread(false);
|
||||
break;
|
||||
@ -58,15 +60,16 @@ void IPCWorkThread::ThreadHandler()
|
||||
invoker->JoinProcessThread(true);
|
||||
break;
|
||||
default:
|
||||
DBINDER_LOGI("policy_ = %{public}d", policy_);
|
||||
DBINDER_LOGI("policy_ = %{public}d", threadObj->policy_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
|
||||
if (current != nullptr) {
|
||||
current->OnThreadTerminated(threadName_);
|
||||
current->OnThreadTerminated(threadObj->threadName_);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void IPCWorkThread::StopWorkThread()
|
||||
@ -81,12 +84,16 @@ void IPCWorkThread::Start(int policy, int proto, std::string threadName)
|
||||
{
|
||||
policy_ = policy;
|
||||
proto_ = proto;
|
||||
|
||||
std::thread t(std::bind(&IPCWorkThread::ThreadHandler, this));
|
||||
pthread_t threadId;
|
||||
int ret = pthread_create(&threadId, NULL, &IPCWorkThread::ThreadHandler, this);
|
||||
std::string wholeName = threadName + std::to_string(getpid()) + "_" + std::to_string(gettid());
|
||||
if (ret != 0) {
|
||||
DBINDER_LOGI("create thread failed");
|
||||
}
|
||||
DBINDER_LOGI("create thread = %{public}s, policy=%d, proto=%d", wholeName.c_str(), policy, proto);
|
||||
thread_ = std::move(t);
|
||||
thread_.detach();
|
||||
if (pthread_detach(threadId) != 0) {
|
||||
DBINDER_LOGI("detach error");
|
||||
}
|
||||
}
|
||||
#ifdef CONFIG_IPC_SINGLE
|
||||
} // namespace IPC_SINGLE
|
||||
|
Loading…
Reference in New Issue
Block a user