+ if (dequeued < min) {
+ status = WaitForSingleObject(wd->iocomplete_event, mswait);
+ if (status != WAIT_OBJECT_0 && dequeued >= min)
+ break;
+ }
+
+ if (dequeued >= min ||
+ (t != NULL && timeout_expired(start_count, end_count)))
+ break;
+ } while (1);
+
+ return dequeued;
+}
+
+static int fio_windowsaio_getevents(struct thread_data *td, unsigned int min,
+ unsigned int max, const struct timespec *t)
+{
+ struct windowsaio_options *o = td->eo;
+
+ if (o->no_completion_thread)
+ return fio_windowsaio_getevents_nothread(td, min, max, t);
+ return fio_windowaio_getevents_thread(td, min, max, t);
+}
+
+static enum fio_q_status fio_windowsaio_queue(struct thread_data *td,
+ struct io_u *io_u)
+{
+ struct fio_overlapped *o = io_u->engine_data;
+ LPOVERLAPPED lpOvl = &o->o;
+ BOOL success = FALSE;
+ int rc = FIO_Q_COMPLETED;
+
+ fio_ro_check(td, io_u);
+
+ lpOvl->Internal = 0;
+ lpOvl->InternalHigh = 0;
+ lpOvl->Offset = io_u->offset & 0xFFFFFFFF;
+ lpOvl->OffsetHigh = io_u->offset >> 32;
+
+ switch (io_u->ddir) {
+ case DDIR_WRITE:
+ success = WriteFile(io_u->file->hFile, io_u->xfer_buf,
+ io_u->xfer_buflen, NULL, lpOvl);
+ break;
+ case DDIR_READ:
+ success = ReadFile(io_u->file->hFile, io_u->xfer_buf,
+ io_u->xfer_buflen, NULL, lpOvl);
+ break;
+ case DDIR_SYNC:
+ case DDIR_DATASYNC:
+ case DDIR_SYNC_FILE_RANGE:
+ success = FlushFileBuffers(io_u->file->hFile);
+ if (!success) {
+ log_err("windowsaio: failed to flush file buffers\n");
+ io_u->error = win_to_posix_error(GetLastError());