70 lines
2.0 KiB
C
70 lines
2.0 KiB
C
#ifndef VY_AIO_H
|
|
#define VY_AIO_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "file_tab.h"
|
|
#include "runtime.h"
|
|
|
|
typedef struct {
|
|
size_t offset; /**< Starting offset inside the file in bytes */
|
|
size_t num_bytes; /**< Number of bytes to load */
|
|
/** Destination buffer with at least @ num_bytes bytes.
|
|
* Must be valid until the load is finished.
|
|
*/
|
|
void *dest;
|
|
vy_file_id file; /**< Unique identifier for the file */
|
|
} vy_file_load;
|
|
|
|
#define VY_LOAD_BATCH_MAX_SIZE 64
|
|
|
|
/** A batch of loads that will be started together.
|
|
*
|
|
* The aio system will hand these to the OS.
|
|
*/
|
|
typedef struct {
|
|
vy_file_load loads[VY_LOAD_BATCH_MAX_SIZE];
|
|
|
|
/** Must be smaller or equal to @c VY_LOAD_BATCH_MAX_SIZE */
|
|
unsigned int num_loads;
|
|
} vy_load_batch;
|
|
|
|
#define VY_AIO_INVALID_HANDLE 0
|
|
|
|
/** Handle for an async io operation. Can be used to query the state and result. */
|
|
typedef uint32_t vy_aio_handle;
|
|
|
|
enum {
|
|
VY_AIO_LOAD_TOO_LARGE = (VY_SUCCESS + 1),
|
|
VY_AIO_TOO_MANY_OPERATIONS,
|
|
VY_AIO_OUT_OF_MEMORY,
|
|
};
|
|
|
|
typedef enum {
|
|
VY_AIO_STATE_INVALID,
|
|
VY_AIO_STATE_PENDING,
|
|
VY_AIO_STATE_FINISHED,
|
|
VY_AIO_STATE_FAILED,
|
|
} vy_aio_state;
|
|
|
|
VY_DLLEXPORT vy_result vySubmitLoadBatch(const vy_load_batch *batch, vy_aio_handle *handles);
|
|
|
|
VY_DLLEXPORT volatile vy_aio_state vyGetAIOState(vy_aio_handle handle);
|
|
|
|
/* Blocks until the given operation is no longer pending.
|
|
* Returns the state that caused the wait to end. The handle is still valid after this function returned. */
|
|
VY_DLLEXPORT vy_aio_state vyWaitForAIOCompletion(vy_aio_handle handle);
|
|
|
|
/* Releases the internal storage for the operation.
|
|
* The system is allowed to re-use the same handle value for new operations after this was called.
|
|
*/
|
|
VY_DLLEXPORT void vyReleaseAIO(vy_aio_handle handle);
|
|
|
|
VY_DLLEXPORT vy_result vySubmitSingleLoad(vy_file_load load, vy_aio_handle *handle);
|
|
|
|
/* Convenience wrapper for a single synchronous file load.
|
|
* Returns the state that caused the wait for completion to return. */
|
|
VY_DLLEXPORT vy_aio_state vySubmitSingleLoadSync(vy_file_load load);
|
|
|
|
#endif
|