| 155 | ****************************************************************************/ |
| 156 | |
| 157 | int work_queue_wq(FAR struct kwork_wqueue_s *wqueue, |
| 158 | FAR struct work_s *work, worker_t worker, |
| 159 | FAR void *arg, clock_t delay) |
| 160 | { |
| 161 | irqstate_t flags; |
| 162 | clock_t expected; |
| 163 | bool retimer; |
| 164 | |
| 165 | if (wqueue == NULL || work == NULL || worker == NULL || |
| 166 | delay > WDOG_MAX_DELAY) |
| 167 | { |
| 168 | return -EINVAL; |
| 169 | } |
| 170 | |
| 171 | expected = clock_delay2abstick(delay); |
| 172 | |
| 173 | /* Interrupts are disabled so that this logic can be called from with |
| 174 | * task logic or from interrupt handling logic. |
| 175 | */ |
| 176 | |
| 177 | flags = spin_lock_irqsave(&wqueue->lock); |
| 178 | |
| 179 | /* Ensure the work has been removed. */ |
| 180 | |
| 181 | retimer = work_available(work) ? false : work_remove(wqueue, work); |
| 182 | |
| 183 | /* Initialize the work structure. */ |
| 184 | |
| 185 | work->worker = worker; /* Work callback. non-NULL means queued */ |
| 186 | work->arg = arg; /* Callback argument */ |
| 187 | work->qtime = expected; /* Expected time */ |
| 188 | |
| 189 | if (delay) |
| 190 | { |
| 191 | /* Insert to the pending list of the wqueue. */ |
| 192 | |
| 193 | if (work_insert_pending(wqueue, work)) |
| 194 | { |
| 195 | /* Start the timer if the work is the earliest expired work. */ |
| 196 | |
| 197 | retimer = false; |
| 198 | wd_start_abstick(&wqueue->timer, work->qtime, |
| 199 | work_timer_expired, (wdparm_t)wqueue); |
| 200 | } |
| 201 | } |
| 202 | else |
| 203 | { |
| 204 | /* Insert to the expired list of the wqueue. */ |
| 205 | |
| 206 | list_add_tail(&wqueue->expired, &work->node); |
| 207 | } |
| 208 | |
| 209 | if (retimer) |
| 210 | { |
| 211 | work_timer_reset(wqueue); |
| 212 | } |
| 213 | |
| 214 | spin_unlock_irqrestore(&wqueue->lock, flags); |
no test coverage detected