| 171 | ****************************************************************************/ |
| 172 | |
| 173 | static inline_function |
| 174 | bool work_insert_pending(FAR struct kwork_wqueue_s *wqueue, |
| 175 | FAR struct work_s *work) |
| 176 | { |
| 177 | FAR struct work_s *curr; |
| 178 | FAR struct work_s *head; |
| 179 | |
| 180 | DEBUGASSERT(wqueue != NULL && work != NULL); |
| 181 | |
| 182 | /* Insert the work into the wait queue sorted by the expired time. */ |
| 183 | |
| 184 | head = list_first_entry(&wqueue->pending, struct work_s, node); |
| 185 | |
| 186 | list_for_every_entry(&wqueue->pending, curr, struct work_s, node) |
| 187 | { |
| 188 | if (!clock_compare(curr->qtime, work->qtime)) |
| 189 | { |
| 190 | break; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /* After the insertion, we do not violate the invariant that |
| 195 | * the wait queue is sorted by the expired time. Because |
| 196 | * curr->qtime > work->qtime. |
| 197 | * In the case of the wqueue is empty, we insert |
| 198 | * the work at the head of the wait queue. |
| 199 | */ |
| 200 | |
| 201 | list_add_before(&curr->node, &work->node); |
| 202 | |
| 203 | /* Return list_is_head(&wqueue->pending, &work->node) |
| 204 | * However, there is fast path that we can check if `curr` |
| 205 | * is the `head` we cached before, which is cache-friendly and |
| 206 | * can reduce one memory access. |
| 207 | */ |
| 208 | |
| 209 | return curr == head; |
| 210 | } |
| 211 | |
| 212 | /**************************************************************************** |
| 213 | * Name: work_remove |
no outgoing calls
no test coverage detected