• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TASK_THREAD_H
17 #define HC_TASK_THREAD_H
18 
19 #include "hc_thread.h"
20 #include "hc_vector.h"
21 
22 typedef struct HcTaskBaseT {
23     void (*doAction) (struct HcTaskBaseT*);
24     void (*destroy) (struct HcTaskBaseT*);
25 } HcTaskBase;
26 
27 typedef struct {
28     HcTaskBase* task;
29 } HcTaskWrap;
30 
31 DECLARE_HC_VECTOR(TaskVec, HcTaskWrap)
32 
33 typedef struct HcTaskThreadT {
34     HcThread thread;
35     TaskVec tasks;
36     int32_t (*startThread)(struct HcTaskThreadT* thread);
37     void (*pushTask) (struct HcTaskThreadT* thread, HcTaskBase* task);
38     void (*clear) (struct HcTaskThreadT* thread);
39     void (*stopAndClear) (struct HcTaskThreadT* thread);
40     HcMutex queueLock;
41     HcBool quit;
42 } HcTaskThread;
43 
44 int32_t InitHcTaskThread(HcTaskThread* thread, size_t stackSize, const char* threadName);
45 void DestroyHcTaskThread(HcTaskThread* thread);
46 #endif