util/async.c: Add async IO worker thread

Need this for IO4 USB emulation, might break it out and upstream it
to Capnhook at some point as well.
This commit is contained in:
Tau
2019-03-03 19:58:11 -05:00
parent 2be3647089
commit ba8b8e32fc
3 changed files with 221 additions and 0 deletions

24
util/async.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include <windows.h>
#include <stdbool.h>
#include "hook/iohook.h"
typedef HRESULT (*async_task_t)(void *ctx, struct irp *irp);
struct async {
CRITICAL_SECTION lock;
CONDITION_VARIABLE pend;
CONDITION_VARIABLE avail;
HANDLE thread;
struct irp irp;
async_task_t task;
void *ctx;
bool stop;
};
void async_init(struct async *async, void *ctx);
void async_fini(struct async *async);
HRESULT async_submit(struct async *async, struct irp *irp, async_task_t task);