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