VirtualBox

source: vbox/trunk/include/iprt/ioqueue.h@ 86649

Last change on this file since 86649 was 85121, checked in by vboxsync, 4 years ago

iprt/cdefs.h: Refactored the typedef use of DECLCALLBACK as well as DECLCALLBACKMEMBER to wrap the whole expression, similar to the DECLR?CALLBACKMEMBER macros. This allows adding a throw() at the end when compiling with the VC++ compiler to indicate that the callbacks won't throw anything, so we can stop supressing the C5039 warning about passing functions that can potential throw C++ exceptions to extern C code that can't necessarily cope with such (unwind,++). Introduced a few _EX variations that allows specifying different/no calling convention too, as that's handy when dynamically resolving host APIs. Fixed numerous places missing DECLCALLBACK and such. Left two angry @todos regarding use of CreateThread. bugref:9794

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.0 KB
Line 
1/** @file
2 * IPRT Generic I/O queue API.
3 */
4
5/*
6 * Copyright (C) 2019-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_ioqueue_h
27#define IPRT_INCLUDED_ioqueue_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/types.h>
33#include <iprt/sg.h>
34
35RT_C_DECLS_BEGIN
36
37/** @defgroup grp_rt_ioqueue IPRT generic I/O queue API
38 * @ingroup grp_rt
39 *
40 * This API models a generic I/O queue which can be attached to different providers
41 * for different types of handles.
42 *
43 * @{
44 */
45
46
47/**
48 * I/O queue request operations.
49 */
50typedef enum RTIOQUEUEOP
51{
52 /** The usual invalid option. */
53 RTIOQUEUEOP_INVALID = 0,
54 /** Read request. */
55 RTIOQUEUEOP_READ,
56 /** Write request. */
57 RTIOQUEUEOP_WRITE,
58 /** Synchronize (i.e. flush) request. */
59 RTIOQUEUEOP_SYNC,
60 /** Usual 32bit hack. */
61 RTIOQUEUEOP_32BIT_HACK = 0x7fffffff
62} RTIOQUEUEOP;
63/** Pointer to a I/O queue operation code. */
64typedef RTIOQUEUEOP *PRTIOQUEUEOP;
65
66/** I/O queue provider (processes requests put into the I/O queue) handle. */
67typedef struct RTIOQUEUEPROVINT *RTIOQUEUEPROV;
68/** I/O queue handle. */
69typedef struct RTIOQUEUEINT *RTIOQUEUE;
70/** Pointer to an I/O queue handle. */
71typedef RTIOQUEUE *PRTIOQUEUE;
72/** NIL I/O queue handle value. */
73#define NIL_RTIOQUEUE ((RTIOQUEUE)0)
74
75
76/**
77 * I/O queue completion event.
78 */
79typedef struct RTIOQUEUECEVT
80{
81 /** The user data passed when preparing the request. */
82 void *pvUser;
83 /** The IPRT status code for this request. */
84 int rcReq;
85 /** Transferred data size if applicaple by the request. */
86 size_t cbXfered;
87} RTIOQUEUECEVT;
88/** Pointer to a I/O queue completion event. */
89typedef RTIOQUEUECEVT *PRTIOQUEUECEVT;
90/** Pointer to a const I/O queue completion event. */
91typedef const RTIOQUEUECEVT *PCRTIOQUEUECEVT;
92
93
94/**
95 * I/O queue provider virtual method table.
96 */
97typedef struct RTIOQUEUEPROVVTABLE
98{
99 /** The structure version (RTIOQUEUEPROVVTABLE_VERSION). */
100 uint32_t uVersion;
101 /** Provider ID. */
102 const char *pszId;
103 /** Size of provider specific data for an I/O queue instance. */
104 size_t cbIoQueueProv;
105 /** The handle type the provider is able to process. */
106 RTHANDLETYPE enmHnd;
107 /** Additional flags for exposing supported features or quirks to the user. */
108 uint32_t fFlags;
109
110 /**
111 * Returns whether the provider is supported on the calling host system.
112 *
113 * @returns Flag whether the provider is supported.
114 */
115 DECLCALLBACKMEMBER(bool, pfnIsSupported,(void));
116
117 /**
118 * Initializes the provider specific parts of the given I/O queue.
119 *
120 * @returns IPRT status code.
121 * @param hIoQueueProv The I/O queue provider instance to initialize.
122 * @param fFlags Flags for the queue.
123 * @param cSqEntries Number of entries for the submission queue.
124 * @param cCqEntries Number of entries for the completion queue.
125 */
126 DECLCALLBACKMEMBER(int, pfnQueueInit,(RTIOQUEUEPROV hIoQueueProv, uint32_t fFlags, uint32_t cSqEntries, uint32_t cCqEntries));
127
128 /**
129 * Destroys the provider specific parts of the I/O queue and frees all
130 * associated resources.
131 *
132 * @returns nothing.
133 * @param hIoQueueProv The I/O queue provider instance to destroy.
134 */
135 DECLCALLBACKMEMBER(void, pfnQueueDestroy,(RTIOQUEUEPROV hIoQueueProv));
136
137 /**
138 * Registers the given handle for use with the I/O queue instance.
139 * The generic code already checked for the correct handle type and that the
140 * handle wasn't registered already by tracking all registered handles.
141 *
142 * @returns IPRT status code.
143 * @param hIoQueueProv The I/O queue provider instance.
144 * @param pHandle The handle to register.
145 */
146 DECLCALLBACKMEMBER(int, pfnHandleRegister,(RTIOQUEUEPROV hIoQueueProv, PCRTHANDLE pHandle));
147
148 /**
149 * Deregisters the given handle for use with the I/O queue instance.
150 * The generic code already checked for the correct handle type and that the
151 * handle was registered previously.
152 *
153 * @returns IPRT status code.
154 * @param hIoQueueProv The I/O queue provider instance.
155 * @param pHandle The handle to deregister.
156 */
157 DECLCALLBACKMEMBER(int, pfnHandleDeregister,(RTIOQUEUEPROV hIoQueueProv, PCRTHANDLE pHandle));
158
159 /**
160 * Prepares a request for the given I/O queue.
161 *
162 * @returns IPRT status code.
163 * @param hIoQueueProv The I/O queue provider instance.
164 * @param pHandle The handle the request is for.
165 * @param enmOp The operation to perform.
166 * @param off Start offset (if applicable, not all handles support/require it and will ignore it).
167 * @param pvBuf Buffer to use for read/write operations (sync ignores this).
168 * @param cbBuf Size of the buffer in bytes.
169 * @param fReqFlags Additional flags for the request.
170 * @param pvUser Opaque user data which is passed back in the completion event.
171 */
172 DECLCALLBACKMEMBER(int, pfnReqPrepare,(RTIOQUEUEPROV hIoQueueProv, PCRTHANDLE pHandle, RTIOQUEUEOP enmOp,
173 uint64_t off, void *pvBuf, size_t cbBuf, uint32_t fReqFlags, void *pvUser));
174
175 /**
176 * Prepares a request for the given I/O queue.
177 *
178 * @returns IPRT status code.
179 * @param hIoQueueProv The I/O queue provider instance.
180 * @param pHandle The handle the request is for.
181 * @param enmOp The operation to perform.
182 * @param off Start offset (if applicable, not all handles support/require it and will ignore it).
183 * @param pSgBuf The S/G buufer to use for read/write operations (sync ignores this).
184 * @param cbSg Number of bytes to transfer from the S/G buffer.
185 * @param fReqFlags Additional flags for the request.
186 * @param pvUser Opaque user data which is passed back in the completion event.
187 */
188 DECLCALLBACKMEMBER(int, pfnReqPrepareSg,(RTIOQUEUEPROV hIoQueueProv, PCRTHANDLE pHandle, RTIOQUEUEOP enmOp,
189 uint64_t off, PCRTSGBUF pSgBuf, size_t cbSg, uint32_t fReqFlags, void *pvUser));
190
191 /**
192 * Commits all prepared requests to the consumer for processing.
193 *
194 * @returns IPRT status code.
195 * @param hIoQueueProv The I/O queue provider instance.
196 * @param pcReqsCommitted Where to store the number of requests actually committed.
197 */
198 DECLCALLBACKMEMBER(int, pfnCommit,(RTIOQUEUEPROV hIoQueueProv, uint32_t *pcReqsCommitted));
199
200 /**
201 * Waits for completion events from the given I/O queue.
202 *
203 * @returns IPRT status code.
204 * @retval VERR_IOQUEUE_EMPTY if there is nothing to wait for.
205 * @param hIoQueueProv The I/O queue provider instance.
206 * @param paCEvt Pointer to the array of completion event entries to fill.
207 * @param cCEvt Size of the completion event entry array.
208 * @param cMinWait Minimum number of completion events to wait for before returning.
209 * @param pcCEvt Where to store the number of completion events on success.
210 * @param fFlags Additional flags controlling the wait behavior.
211 */
212 DECLCALLBACKMEMBER(int, pfnEvtWait,(RTIOQUEUEPROV hIoQueueProv, PRTIOQUEUECEVT paCEvt, uint32_t cCEvt,
213 uint32_t cMinWait, uint32_t *pcCEvt, uint32_t fFlags));
214
215 /**
216 * Wakes up the thread waiting in RTIOQUEUEPROVVTABLE::pfnEvtWait().
217 *
218 * @returns IPRT status code.
219 * @param hIoQueueProv The I/O queue provider instance.
220 */
221 DECLCALLBACKMEMBER(int, pfnEvtWaitWakeup,(RTIOQUEUEPROV hIoQueueProv));
222
223 /** Marks the end of the structure (RTIOQUEUEPROVVTABLE_VERSION). */
224 uintptr_t uEndMarker;
225} RTIOQUEUEPROVVTABLE;
226/** Pointer to an I/O queue provider vtable. */
227typedef RTIOQUEUEPROVVTABLE *PRTIOQUEUEPROVVTABLE;
228/** Pointer to a const I/O queue provider vtable. */
229typedef RTIOQUEUEPROVVTABLE const *PCRTIOQUEUEPROVVTABLE;
230
231/** The RTIOQUEUEPROVVTABLE structure version. */
232#define RTIOQUEUEPROVVTABLE_VERSION RT_MAKE_U32_FROM_U8(0xff,0xf,1,0)
233
234/** @name RTIOQUEUEPROVVTABLE::fFlags
235 * @{ */
236/** Provider supports S/G lists. */
237#define RTIOQUEUEPROVVTABLE_F_SG RT_BIT_32(0)
238/** Mask of the valid I/O stream feature flags. */
239#define RTIOQUEUEPROVVTABLE_F_VALID_MASK UINT32_C(0x00000001)
240/** @} */
241
242
243/**
244 * Tries to return the best I/O queue provider for the given handle type on the called
245 * host system.
246 *
247 * @returns Pointer to the I/O queue provider handle table or NULL if no suitable
248 * provider was found for the given handle type.
249 * @param enmHnd The handle type to look for a provider.
250 */
251RTDECL(PCRTIOQUEUEPROVVTABLE) RTIoQueueProviderGetBestForHndType(RTHANDLETYPE enmHnd);
252
253
254/**
255 * Returns the I/O queue provider with the given ID.
256 *
257 * @returns Pointer to the I/O queue provider handle table or NULL if no provider with
258 * the given ID was found.
259 * @param pszId The ID to look for.
260 */
261RTDECL(PCRTIOQUEUEPROVVTABLE) RTIoQueueProviderGetById(const char *pszId);
262
263
264/**
265 * Creates a new I/O queue with the given consumer.
266 *
267 * @returns IPRT status code.
268 * @param phIoQueue Where to store the handle to the I/O queue on success.
269 * @param pProvVTable The I/O queue provider vtable which will process the requests.
270 * @param fFlags Flags for the queue (MBZ for now).
271 * @param cSqEntries Number of entries for the submission queue.
272 * @param cCqEntries Number of entries for the completion queue.
273 *
274 * @note The number of submission and completion queue entries serve only as a hint to the
275 * provider implementation. It may decide to align the number to a smaller or greater
276 * size.
277 */
278RTDECL(int) RTIoQueueCreate(PRTIOQUEUE phIoQueue, PCRTIOQUEUEPROVVTABLE pProvVTable,
279 uint32_t fFlags, uint32_t cSqEntries, uint32_t cCqEntries);
280
281
282/**
283 * Destroys the given I/O queue.
284 *
285 * @returns IPRT status code.
286 * @retval VERR_IOQUEUE_BUSY if the I/O queue is still processing requests.
287 * @param hIoQueue The I/O queue handle to destroy.
288 */
289RTDECL(int) RTIoQueueDestroy(RTIOQUEUE hIoQueue);
290
291
292/**
293 * Registers the given handle for use with the I/O queue.
294 *
295 * @returns IPRT status code.
296 * @retval VERR_ALREADY_EXISTS if the handle was already registered.
297 * @retval VERR_NOT_SUPPORTED if the handle type is not supported by the consumer
298 * for the given I/O queue.
299 * @param hIoQueue The I/O queue handle.
300 * @param pHandle The handle to register.
301 */
302RTDECL(int) RTIoQueueHandleRegister(RTIOQUEUE hIoQueue, PCRTHANDLE pHandle);
303
304
305/**
306 * Deregisters the given handle from the given I/O queue.
307 *
308 * @returns IPRT status code.
309 * @retval VERR_IOQUEUE_HANDLE_NOT_REGISTERED if the handle wasn't registered by a call to RTIoQueueHandleRegister().
310 * @param hIoQueue The I/O queue handle.
311 * @param pHandle The handle to deregister.
312 */
313RTDECL(int) RTIoQueueHandleDeregister(RTIOQUEUE hIoQueue, PCRTHANDLE pHandle);
314
315
316/**
317 * Prepares a request for the given I/O queue.
318 *
319 * @returns IPRT status code.
320 * @retval VERR_IOQUEUE_FULL if the I/O queue can't accept the new request because the submission queue is full.
321 * @retval VERR_IOQUEUE_HANDLE_NOT_REGISTERED if the handle wasn't registered for use with RTIoQueueHandleRegister() yet.
322 * @param hIoQueue The I/O queue handle.
323 * @param pHandle The handle the request is for.
324 * @param enmOp The operation to perform.
325 * @param off Start offset (if applicable, not all handles support/require it and will ignore it).
326 * @param pvBuf Buffer to use for read/write operations (sync ignores this).
327 * @param cbBuf Size of the buffer in bytes.
328 * @param fReqFlags Additional flags for the request.
329 * @param pvUser Opaque user data which is passed back in the completion event.
330 */
331RTDECL(int) RTIoQueueRequestPrepare(RTIOQUEUE hIoQueue, PCRTHANDLE pHandle, RTIOQUEUEOP enmOp,
332 uint64_t off, void *pvBuf, size_t cbBuf, uint32_t fReqFlags,
333 void *pvUser);
334
335
336/**
337 * Prepares a request for the given I/O queue - S/G buffer variant.
338 *
339 * @returns IPRT status code.
340 * @retval VERR_IOQUEUE_FULL if the I/O queue can't accept the new request because the submission queue is full.
341 * @retval VERR_IOQUEUE_HANDLE_NOT_REGISTERED if the handle wasn't registered for use with RTIoQueueHandleRegister() yet.
342 * @param hIoQueue The I/O queue handle.
343 * @param pHandle The handle the request is for.
344 * @param enmOp The operation to perform.
345 * @param off Start offset (if applicable, not all handles support/require it and will ignore it).
346 * @param pSgBuf The S/G buufer to use for read/write operations (sync ignores this).
347 * @param cbSg Number of bytes to transfer from the S/G buffer.
348 * @param fReqFlags Additional flags for the request.
349 * @param pvUser Opaque user data which is passed back in the completion event.
350 */
351RTDECL(int) RTIoQueueRequestPrepareSg(RTIOQUEUE hIoQueue, PCRTHANDLE pHandle, RTIOQUEUEOP enmOp,
352 uint64_t off, PCRTSGBUF pSgBuf, size_t cbSg, uint32_t fReqFlags,
353 void *pvUser);
354
355
356/**
357 * Commits all prepared requests to the consumer for processing.
358 *
359 * @returns IPRT status code.
360 * @retval VERR_IOQUEUE_EMPTY if there is nothing to commit.
361 * @param hIoQueue The I/O queue handle.
362 */
363RTDECL(int) RTIoQueueCommit(RTIOQUEUE hIoQueue);
364
365
366/**
367 * Waits for completion events from the given I/O queue.
368 *
369 * @returns IPRT status code.
370 * @retval VERR_IOQUEUE_EMPTY if there is nothing to wait for.
371 * @param hIoQueue The I/O queue handle.
372 * @param paCEvt Pointer to the array of completion event entries to fill.
373 * @param cCEvt Size of the completion event entry array.
374 * @param cMinWait Minimum number of completion events to wait for before returning.
375 * @param pcCEvt Where to store the number of completion events on success.
376 * @param fFlags Additional flags controlling the wait behavior.
377 */
378RTDECL(int) RTIoQueueEvtWait(RTIOQUEUE hIoQueue, PRTIOQUEUECEVT paCEvt, uint32_t cCEvt, uint32_t cMinWait,
379 uint32_t *pcCEvt, uint32_t fFlags);
380
381
382/**
383 * Wakes up the thread waiting in RTIoQueueEvtWait().
384 *
385 * @returns IPRT status code.
386 * @param hIoQueue The I/O queue handle to wake up.
387 */
388RTDECL(int) RTIoQueueEvtWaitWakeup(RTIOQUEUE hIoQueue);
389
390/** @} */
391
392RT_C_DECLS_END
393
394#endif /* !IPRT_INCLUDED_ioqueue_h */
395
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette