/*
* Native Windows async IO engine
- * Copyright (C) 2011 Bruce Cran <bruce@cran.org.uk>
+ * Copyright (C) 2012 Bruce Cran <bruce@cran.org.uk>
*/
#include <stdio.h>
}
if (!rc) {
- for (i = 0; i < td->o.iodepth; i++) {
- wd->ovls[i].io_free = TRUE;
- wd->ovls[i].io_complete = FALSE;
+ for (i = 0; i < td->o.iodepth; i++) {
+ wd->ovls[i].io_free = TRUE;
+ wd->ovls[i].io_complete = FALSE;
wd->ovls[i].o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (wd->ovls[i].o.hEvent == NULL) {
rc = 1;
break;
}
- }
+ }
}
if (!rc) {
}
hKernel32Dll = GetModuleHandle("kernel32.dll");
- wd->pCancelIoEx = GetProcAddress(hKernel32Dll, "CancelIoEx");
-
+ wd->pCancelIoEx = (CANCELIOEX)GetProcAddress(hKernel32Dll, "CancelIoEx");
td->io_ops->data = wd;
+
return rc;
}
CloseHandle(wd->iothread);
CloseHandle(wd->iocomplete_event);
- for (i = 0; i < td->o.iodepth; i++)
+ for (i = 0; i < td->o.iodepth; i++) {
CloseHandle(wd->ovls[i].o.hEvent);
+ }
free(wd->aio_events);
free(wd->ovls);
if (td->o.sync_io)
flags |= FILE_FLAG_WRITE_THROUGH;
+ /*
+ * Inform Windows whether we're going to be doing sequential or
+ * random io so it can tune the Cache Manager
+ */
if (td->o.td_ddir == TD_DDIR_READ ||
td->o.td_ddir == TD_DDIR_WRITE)
flags |= FILE_FLAG_SEQUENTIAL_SCAN;
else
access = (GENERIC_READ | GENERIC_WRITE);
- if (td->o.create_on_open > 0)
+ if (td->o.create_on_open)
openmode = OPEN_ALWAYS;
else
openmode = OPEN_EXISTING;
if (f->hFile == INVALID_HANDLE_VALUE)
rc = 1;
- /* Only set up the competion port and thread if we're not just
+ /* Only set up the completion port and thread if we're not just
* querying the device size */
if (!rc && td->io_ops->data != NULL) {
struct thread_ctx *ctx;
if (fov->io_complete) {
fov->io_complete = FALSE;
fov->io_free = TRUE;
+ ResetEvent(fov->o.hEvent);
wd->aio_events[dequeued] = io_u;
dequeued++;
}
if (dequeued < min) {
status = WaitForSingleObject(wd->iocomplete_event, mswait);
- if (status != WAIT_OBJECT_0 && dequeued > 0)
+ if (status != WAIT_OBJECT_0 && dequeued >= min)
break;
}
LPOVERLAPPED lpOvl = NULL;
struct windowsaio_data *wd;
DWORD iobytes;
- BOOL success;
+ BOOL success = FALSE;
int index;
int rc = FIO_Q_COMPLETED;
wd = td->io_ops->data;
for (index = 0; index < td->o.iodepth; index++) {
- if (wd->ovls[index].io_free) {
- wd->ovls[index].io_free = FALSE;
- ResetEvent(wd->ovls[index].o.hEvent);
+ if (wd->ovls[index].io_free)
break;
- }
}
assert(index < td->o.iodepth);
- lpOvl = &wd->ovls[index].o;
+ wd->ovls[index].io_free = FALSE;
wd->ovls[index].io_u = io_u;
+ lpOvl = &wd->ovls[index].o;
lpOvl->Internal = STATUS_PENDING;
lpOvl->InternalHigh = 0;
lpOvl->Offset = io_u->offset & 0xFFFFFFFF;
break;
default:
assert(0);
+ break;
}
if (success || GetLastError() == ERROR_IO_PENDING)