• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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 __HI_QUEUE_H__
17 #define __HI_QUEUE_H__
18 #include "hi_types.h"
19 #include <linux/workqueue.h>
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif
26 
27 typedef hi_void (*work_func)(struct work_struct *);
28 typedef struct workqueue_struct     hi_workqueue;
29 typedef struct work_struct          hi_work;
30 typedef struct delayed_work         hi_delayed_work; /* struct delay_work wrap struct work_struct */
31 
32 /* create workqueue. */
hi_workqueue_create(char * workqueue_name)33 inline hi_workqueue *hi_workqueue_create(char *workqueue_name)
34 {
35     return create_workqueue(workqueue_name);
36 }
37 
38 /* destroy workqueue. */
hi_workqueue_destroy(hi_workqueue * workqueue)39 inline hi_void  hi_workqueue_destroy(hi_workqueue *workqueue)
40 {
41     destroy_workqueue(workqueue);
42 }
43 
44 /* init work. */
hi_workqueue_init_work(hi_work * work,work_func func)45 inline hi_void hi_workqueue_init_work(hi_work *work, work_func func)
46 {
47     INIT_WORK(work, func);
48 }
49 
50 /* add work to workqueue. */
hi_workqueue_add_work(hi_workqueue * workqueue,hi_work * work)51 inline hi_s32  hi_workqueue_add_work(hi_workqueue *workqueue, hi_work *work)
52 {
53     return queue_work(workqueue, work);
54 }
55 
56 /* cancle work from workqueue. */
hi_workqueue_cancle_work_sync(hi_work * work)57 inline hi_bool hi_workqueue_cancle_work_sync(hi_work *work)
58 {
59     return cancel_work_sync(work);
60 }
61 
62 /* judge work is working. */
hi_workqueue_is_busy(hi_work * work)63 inline hi_bool hi_workqueue_is_busy(hi_work *work)
64 {
65     return work_busy(work);
66 }
67 
68 /* init delayed work. */
hi_workqueue_init_delayed_work(hi_delayed_work * delayed_work,work_func func)69 inline hi_void hi_workqueue_init_delayed_work(hi_delayed_work *delayed_work, work_func func)
70 {
71     init_delayed_work(delayed_work, func);
72 }
73 
74 /* add delay work to workqueue. */
hi_workqueue_add_delayed_work(hi_workqueue * workqueue,hi_delayed_work * delayed_work,hi_u32 delay)75 inline hi_s32 hi_workqueue_add_delayed_work(hi_workqueue *workqueue, hi_delayed_work *delayed_work, hi_u32 delay)
76 {
77     return queue_delayed_work(workqueue, delayed_work, delay);
78 }
79 
80 /* cancle delayed work to workqueue. */
hi_workqueue_cancle_delayed_work_sync(hi_delayed_work * delayed_work)81 inline hi_bool hi_workqueue_cancle_delayed_work_sync(hi_delayed_work *delayed_work)
82 {
83     return cancel_delayed_work_sync(delayed_work);
84 }
85 
86 #ifdef __cplusplus
87 #if __cplusplus
88 }
89 #endif
90 #endif
91 
92 #endif /* end of hi_workqueue.h */
93