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 HC_THREAD_H 17 #define HC_THREAD_H 18 19 #include "pthread.h" 20 #include "hc_types.h" 21 #include "hc_string.h" 22 #include "hc_condition.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 typedef int (*ThreadFunc)(void*); 29 30 typedef struct HcThreadT { 31 ThreadFunc threadFunc; 32 int (*start)(struct HcThreadT* thread); 33 void(*join)(struct HcThreadT* thread); 34 void (*wait)(struct HcThreadT* thread); 35 void (*notify)(struct HcThreadT* thread); 36 pthread_t thread; 37 size_t stackSize; 38 HcBool running; 39 HcString name; 40 HcCondition threadWaitObj; 41 HcMutex threadLock; 42 HcCondition bizWaitObj; 43 } HcThread; 44 45 int32_t InitThread(HcThread* thread, ThreadFunc func, size_t stackSize, const char* threadName); 46 void DestroyThread(HcThread* thread); 47 48 #ifdef __cplusplus 49 } 50 #endif 51 #endif