1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 
5 #include "cpp_workQueue.h"
6 
7 using namespace AOS;
8 
9 /**
10  * This function will creat a workqueue
11  * @param[in]  name        the name of workqueue/worker, which should be unique
12  * @param[in]  pri         the priority of the worker
13  * @param[in]  stack_buf   the stack of the worker(task)
14  * @param[in]  stack_size  the size of the worker-stack
15  * @return  the operation status, RHINO_SUCCESS is OK, others is error
16  */
create(const name_t * name,uint8_t pri,cpu_stack_t * stack_buf,size_t stack_size)17 kstat_t WorkQueue::create(const name_t *name, uint8_t pri, cpu_stack_t *stack_buf, size_t stack_size)
18 {
19     return krhino_workqueue_create(&_workqueue_def, name, pri, stack_buf, stack_size / sizeof(cpu_stack_t));
20 }
21 
22 /**
23  * This function will delete a workqueue
24  * @param[in]  none
25  * @return  the operation status, RHINO_SUCCESS is OK, others is error
26  */
destory(void)27 kstat_t WorkQueue::destory(void)
28 {
29     return kstat_t(0);
30 }
31 
32 /**
33  * This function will get a workqueue struct pointer
34  * @param[in]  none
35  * @return  workqueue struct pointer
36  */
self(void)37 kworkqueue_t *WorkQueue::self(void)
38 {
39 	return &_workqueue_def;
40 }
41 
42 /**
43  * This function will initialize a work
44  * @param[in]  handle  the call back function to run
45  * @param[in]  arg     the paraments of the function
46  * @param[in]  dly     the ticks to delay before run
47  * @return  the operation status, RHINO_SUCCESS is OK, others is error
48  */
init(work_handle_t handle,void * arg,tick_t dly)49 kstat_t Work::init(work_handle_t handle, void *arg, tick_t dly)
50 {
51     return krhino_work_init(&_work_def, handle, arg, dly);
52 }
53 
54 /**
55  * This function will run a work on a workqueue
56  * @param[in]  workqueue  the workqueue to run work
57  * @return  the operation status, RHINO_SUCCESS is OK, others is error
58  */
run(kworkqueue_t * workqueue)59 kstat_t Work::run(kworkqueue_t *workqueue)
60 {
61     return krhino_work_run(workqueue, &_work_def);
62 }
63 
64 /**
65  * This function will run a work on the default workqueue
66  * @param[in]  none
67  * @return  the operation status, RHINO_SUCCESS is OK, others is error
68  */
sched(void)69 kstat_t Work::sched(void)
70 {
71     return krhino_work_sched(&_work_def);
72 }
73 
74 /**
75  * This function will cancel a work
76  * @param[in]  none
77  * @return  the operation status, RHINO_SUCCESS is OK, others is error
78  */
cancel(void)79 kstat_t Work::cancel(void)
80 {
81     return krhino_work_cancel(&_work_def);
82 }
83 
84 /**
85  * This function will get a Work struct pointer
86  * @param[in]  none
87  * @return  Work struct pointer
88  */
self(void)89 kwork_t *Work::self(void)
90 {
91 	return &_work_def;
92 }
93