1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_IPC_RPC_THRREAD_H 17 #define OHOS_IPC_RPC_THRREAD_H 18 19 #include <pthread.h> 20 #include <stdbool.h> 21 22 #include "ipc_skeleton.h" 23 #include "iremote_invoker.h" 24 #include "dbinder_types.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif /* __cplusplus */ 29 30 enum { 31 SPAWN_PASSIVE, 32 SPAWN_ACTIVE, 33 PROCESS_PASSIVE, 34 PROCESS_ACTIVE, 35 }; 36 37 typedef struct { 38 pthread_t threadId; 39 int32_t proto; 40 int32_t policy; 41 IpcObjectStub *objectStub; 42 pid_t callerPid; 43 pid_t callerUid; 44 char callerDeviceID[DEVICEID_LENGTH + 1]; 45 bool stopWorkThread; 46 uint64_t seqNumber; 47 uint32_t sessionId; 48 } ThreadContext; 49 50 typedef struct { 51 int32_t maxThreadNum; 52 int32_t idleThreadNum; 53 int32_t idleSocketThreadNum; 54 pthread_mutex_t lock; 55 } ThreadPool; 56 57 ThreadPool *InitThreadPool(int32_t maxThreadNum); 58 59 void DeinitThreadPool(ThreadPool *threadPool); 60 61 int32_t SpawnNewThread(ThreadPool *threadPool, int32_t policy, int32_t proto); 62 63 ThreadContext *GetCurrentThreadContext(void); 64 65 RemoteInvoker *GetRemoteInvoker(void); 66 67 void UpdateMaxThreadNum(ThreadPool *threadPool, int32_t maxThreadNum); 68 69 #ifdef __cplusplus 70 } 71 #endif /* __cplusplus */ 72 #endif /* OHOS_IPC_RPC_THRREAD_H */