Push a task to the end of the queue
| 30 | |
| 31 | // Push a task to the end of the queue |
| 32 | void push(async::task_run_handle t) { |
| 33 | // Resize queue if it is full |
| 34 | if (head == ((tail + 1) & (items.size() - 1))) { |
| 35 | async::detail::aligned_array<void*, LIBASYNC_CACHELINE_SIZE> new_items( |
| 36 | items.size() * 2); |
| 37 | for (std::size_t i = 0; i != items.size(); i++) |
| 38 | new_items[i] = items[(i + head) & (items.size() - 1)]; |
| 39 | head = 0; |
| 40 | tail = items.size() - 1; |
| 41 | items = std::move(new_items); |
| 42 | } |
| 43 | |
| 44 | // Push the item |
| 45 | items[tail] = t.to_void_ptr(); |
| 46 | tail = (tail + 1) & (items.size() - 1); |
| 47 | } |
| 48 | |
| 49 | // Pop a task from the front of the queue |
| 50 | async::task_run_handle pop() { |
no test coverage detected