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

!233 IPC:lock optimization & modify __cplusplus

Merge pull request !233 from liubb_0516/master
......@@ -19,10 +19,8 @@
#include <stdint.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
int32_t StartDBinderService(void);
int32_t RegisterRemoteProxy(const void *name, uint32_t len, int32_t systemAbility);
......@@ -30,8 +28,6 @@ int32_t MakeRemoteBinder(const void *serviceName, uint32_t nameLen, const char *
uintptr_t binderObject, uint64_t pid, void *remoteObject);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* DBINDER_SERVICE_H */
\ No newline at end of file
......@@ -24,9 +24,7 @@
#include "serializer.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
enum {
......@@ -78,8 +76,6 @@ int32_t MessageOptionInit(MessageOption *option);
int32_t ReleaseSvc(SvcIdentity target);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* OHOS_IPC_RPC_SKELETON_H */
......@@ -21,10 +21,8 @@
#include <stdint.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct {
char *bufferBase;
......@@ -128,9 +126,7 @@ float *ReadFloatVector(IpcIo *io, size_t *size);
double *ReadDoubleVector(IpcIo *io, size_t *size);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* OHOS_IPC_RPC_SERIALIZER_H */
......@@ -19,17 +19,14 @@
#include <stdint.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
int32_t RpcGetPid(void);
int32_t RpcGetUid(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* OHOS_IPC_RPC_OS_ADAPTER_H */
......@@ -19,16 +19,12 @@
#include "iremote_invoker.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
RemoteInvoker *GetIpcInvoker(void);
void DeinitIpcInvoker(RemoteInvoker *invoker);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* OHOS_IPC_INVOKER_H */
\ No newline at end of file
......@@ -24,9 +24,7 @@
#include "utils_list.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
typedef struct {
......@@ -74,8 +72,6 @@ void WaitForProxyInit(SvcIdentity *svc);
int32_t DeleteHandle(int32_t handle);
void ResetIpc(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* OHOS_IPC_RPC_PROCESS_SKELETON_H */
\ No newline at end of file
......@@ -24,9 +24,7 @@
#include "dbinder_types.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
enum {
......@@ -69,8 +67,6 @@ RemoteInvoker *GetRemoteInvoker(void);
void UpdateMaxThreadNum(ThreadPool *threadPool, int32_t maxThreadNum);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* OHOS_IPC_RPC_THRREAD_H */
\ No newline at end of file
......@@ -21,9 +21,7 @@
#include "serializer.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
typedef struct {
......@@ -46,8 +44,6 @@ typedef struct {
RemoteInvoker *InitRemoteInvoker(int32_t proto);
void DeinitRemoteInvoker(RemoteInvoker *invoker, int32_t proto);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* OHOS_IPC_RPC_IREMOTTE_INVOKER_H */
\ No newline at end of file
......@@ -29,10 +29,8 @@
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#ifndef IPCRPC_DEBUG
#if defined(__LITEOS_M__)
......@@ -110,8 +108,6 @@ typedef enum {
void RpcLog(RpcLogModule module, RpcLogLevel level, const char *fmt, ...);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* OHOS_IPC_RPC_LOG_H */
\ No newline at end of file
......@@ -19,18 +19,14 @@
#include "serializer.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
void *IoPush(IpcIo *io, size_t size);
void *IoPop(IpcIo *io, size_t size);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* OHOS_IPC_RPC_SERIALIZER_INNER_H */
......@@ -150,6 +150,12 @@ int32_t SpawnNewThread(ThreadPool *threadPool, int32_t policy, int32_t proto)
RPC_LOG_ERROR("get thread pool lock failed.");
return ERR_FAILED;
}
if (!(proto == IF_PROT_BINDER && threadPool->idleThreadNum > 0) &&
!(proto == IF_PROT_DATABUS && threadPool->idleSocketThreadNum > 0)) {
pthread_mutex_unlock(&threadPool->lock);
RPC_LOG_ERROR("thread pool is full.");
return ERR_INVALID_PARAM;
}
ThreadContext *threadContext = (ThreadContext *)calloc(1, sizeof(ThreadContext));
if (threadContext == NULL) {
pthread_mutex_unlock(&threadPool->lock);
......@@ -178,15 +184,16 @@ int32_t SpawnNewThread(ThreadPool *threadPool, int32_t policy, int32_t proto)
void UpdateMaxThreadNum(ThreadPool *threadPool, int32_t maxThreadNum)
{
int32_t totalNum = maxThreadNum + maxThreadNum;
if (pthread_mutex_lock(&threadPool->lock) != 0) {
RPC_LOG_ERROR("get thread pool lock failed.");
return;
}
int32_t oldThreadNum = threadPool->maxThreadNum;
if (totalNum <= oldThreadNum) {
pthread_mutex_unlock(&threadPool->lock);
RPC_LOG_ERROR("not support set lower max thread num.");
return;
}
if (pthread_mutex_lock(&threadPool->lock) != 0) {
RPC_LOG_ERROR("get thread pool lock failed.");
return;
}
int32_t diff = totalNum - oldThreadNum;
threadPool->maxThreadNum = totalNum;
threadPool->idleThreadNum += diff / PROTO_NUM;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册