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 * Description: OS Abstract Layer. 15 */ 16 17 /** 18 * @defgroup osal_delayedwork osal_delayedwork 19 */ 20 #ifndef __OSAL_DELAYWORK_H__ 21 #define __OSAL_DELAYWORK_H__ 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif 27 #endif 28 29 typedef struct osal_delayedwork_ { 30 void *work; 31 void (*handler)(struct osal_delayedwork_ *delayedwork); 32 } osal_delayedwork; 33 typedef void (*osal_delayedwork_handler)(osal_delayedwork *delayedwork); 34 35 /** 36 * @ingroup osal_delayedwork 37 * @brief This API is used to initialization of delayedwork. 38 * 39 * @par Description: 40 * This API is used to initialization of delayedwork. 41 * 42 * @attention Must be freed with osal_delayedwork_destroy. 43 * 44 * @param work [in/out] The delayedwork to be initialized. 45 * @param handler [in/out] The delayedwork callback handler function. 46 * 47 * @return OSAL_SUCCESS/OSAL_FAILURE 48 * 49 * @par Support System: 50 * linux. 51 */ 52 int osal_delayedwork_init(osal_delayedwork *work, osal_delayedwork_handler handler); 53 54 /** 55 * @ingroup osal_delayedwork 56 * @brief This API is used to destroy the delayedwork. 57 * 58 * @par Description: 59 * This API is used to destroy the delayedwork. 60 * 61 * @param work [in] The delayedwork to be destroyed. 62 * 63 * @attention this api may free memory, work should be from osal_delayedwork_init. 64 * 65 * @par Support System: 66 * linux. 67 */ 68 void osal_delayedwork_destroy(osal_delayedwork *work); 69 70 /** 71 * @ingroup osal_delayedwork 72 * @brief put work task in global workqueue after delay. 73 * 74 * @par Description: 75 * put work task in global workqueue after delay. 76 * After waiting for a given time this puts a job in the kernel-global workqueue. 77 * 78 * @param work [in] Job to be done. 79 * @param timeout [in] Number of jiffies to wait or 0 for immediate execution. 80 * 81 * @return OSAL_SUCCESS/OSAL_FAILURE 82 * 83 * @par Support System: 84 * linux. 85 */ 86 int osal_delayedwork_schedule(osal_delayedwork *work, int timeout); 87 88 /** 89 * @ingroup osal_delayedwork 90 * @brief cancel a delayed work and wait for it to finish. 91 * 92 * @par Description: 93 * cancel a delayed work and wait for it to finish. 94 * 95 * @param work [in] The delayed work cancel. 96 * 97 * @return OSAL_SUCCESS/OSAL_FAILURE 98 * 99 * @par Support System: 100 * linux. 101 */ 102 int osal_delayedwork_cancel_sync(osal_delayedwork *work); 103 104 #ifdef __cplusplus 105 #if __cplusplus 106 } 107 #endif 108 #endif 109 #endif /* __OSAL_DELAYWORK_H__ */