+ if (svm_fifo_chunk_includes_pos (c, start_pos))
+ f->ooo_deq = c;
+
+ if (svm_fifo_chunk_includes_pos (c, end_pos) && ref_pos < end_pos)
+ return;
+
+ do
+ {
+ c = c->next;
+ if (c->rb_index != RBTREE_TNIL_INDEX)
+ break;
+
+ c->rb_index = rb_tree_add2 (rt, c->start_byte, pointer_to_uword (c));
+
+ if (svm_fifo_chunk_includes_pos (c, start_pos))
+ f->ooo_deq = c;
+
+ }
+ while (!svm_fifo_chunk_includes_pos (c, end_pos));
+}
+
+void
+svm_fifo_ooo_deq_track (svm_fifo_t * f, u32 start_pos, u32 end_pos)
+{
+ rb_tree_t *rt = &f->ooo_deq_lookup;
+ svm_fifo_chunk_t *c;
+
+ if (svm_fifo_chunk_includes_pos (f->ooo_deq, end_pos)
+ && start_pos < end_pos)
+ return;
+
+ c = f->ooo_deq->next;
+ do
+ {
+ ASSERT (c->rb_index == RBTREE_TNIL_INDEX);
+ rb_tree_add2 (rt, c->start_byte, pointer_to_uword (c));
+
+ c = c->next;
+ }
+ while (!svm_fifo_chunk_includes_pos (c, end_pos));
+}
+
+static svm_fifo_chunk_t *
+svm_fifo_lookup_clear_chunks (svm_fifo_t * f, rb_tree_t * rt,
+ svm_fifo_chunk_t * start, u32 start_pos,
+ u32 end_pos)
+{
+ svm_fifo_chunk_t *c;
+ rb_node_t *n;
+
+ /* Nothing to do if still in the same chunk and not wrapped */
+ if (svm_fifo_chunk_includes_pos (start, end_pos) && start_pos < end_pos)
+ return start;
+
+ c = start;
+ do
+ {
+ if (c->rb_index == RBTREE_TNIL_INDEX)
+ {
+ c = c->next;
+ continue;
+ }
+
+ n = rb_node (rt, c->rb_index);
+ rb_tree_del_node (rt, n);
+ c->rb_index = RBTREE_TNIL_INDEX;
+ c = c->next;
+ }
+ while (!svm_fifo_chunk_includes_pos (c, end_pos));
+
+ return c;