+static void fio_syslet_complete_atom(struct thread_data *td,
+ struct syslet_uatom *atom)
+{
+ struct syslet_data *sd = td->io_ops->data;
+ struct io_u *io_u;
+ int i, end;
+
+ if (!sd->event_map_idx)
+ return;
+
+ /*
+ * Find the start of the string of atoms for this sequence
+ */
+ for (end = sd->event_map_idx - 1; end >= 0; end--)
+ if (atom == sd->event_map[end])
+ break;
+
+ if (end < 0 || atom != sd->event_map[end]) {
+ printf("didn't find atom\n");
+ return;
+ }
+
+ //printf("end=%d, total %d\n", end, sd->event_map_idx);
+
+ /*
+ * now complete in right order
+ */
+ for (i = 0; i <= end; i++) {
+ long ret;
+
+ atom = sd->event_map[i];
+ io_u = atom->private;
+ ret = *atom->ret_ptr;
+ if (ret > 0)
+ io_u->resid = io_u->xfer_buflen - ret;
+ else if (ret < 0)
+ io_u->error = ret;
+
+ assert(sd->nr_events < td->iodepth);
+ sd->events[sd->nr_events++] = io_u;
+ }
+
+ /*
+ * Move later completions to the front, if we didn't complete all
+ */
+ if (end == (int) sd->event_map_idx - 1)
+ sd->event_map_idx = 0;
+ else {
+ int nr = sd->event_map_idx - end - 1;
+
+ memmove(sd->event_map, &sd->event_map[end + 1], nr * sizeof(struct syslet_uatom *));
+ sd->event_map_idx = nr;
+ }
+}
+