SDL_asyncio.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /* WIKI CATEGORY: AsyncIO */
  19. /**
  20. * # CategoryAsyncIO
  21. *
  22. * SDL offers a way to perform I/O asynchronously. This allows an app to read
  23. * or write files without waiting for data to actually transfer; the functions
  24. * that request I/O never block while the request is fulfilled.
  25. *
  26. * Instead, the data moves in the background and the app can check for results
  27. * at their leisure.
  28. *
  29. * This is more complicated than just reading and writing files in a
  30. * synchronous way, but it can allow for more efficiency, and never having
  31. * framerate drops as the hard drive catches up, etc.
  32. *
  33. * The general usage pattern for async I/O is:
  34. *
  35. * - Create one or more SDL_AsyncIOQueue objects.
  36. * - Open files with SDL_AsyncIOFromFile.
  37. * - Start I/O tasks to the files with SDL_ReadAsyncIO or SDL_WriteAsyncIO,
  38. * putting those tasks into one of the queues.
  39. * - Later on, use SDL_GetAsyncIOResult on a queue to see if any task is
  40. * finished without blocking. Tasks might finish in any order with success
  41. * or failure.
  42. * - When all your tasks are done, close the file with SDL_CloseAsyncIO. This
  43. * also generates a task, since it might flush data to disk!
  44. *
  45. * This all works, without blocking, in a single thread, but one can also wait
  46. * on a queue in a background thread, sleeping until new results have arrived:
  47. *
  48. * - Call SDL_WaitAsyncIOResult from one or more threads to efficiently block
  49. * until new tasks complete.
  50. * - When shutting down, call SDL_SignalAsyncIOQueue to unblock any sleeping
  51. * threads despite there being no new tasks completed.
  52. *
  53. * And, of course, to match the synchronous SDL_LoadFile, we offer
  54. * SDL_LoadFileAsync as a convenience function. This will handle allocating a
  55. * buffer, slurping in the file data, and null-terminating it; you still check
  56. * for results later.
  57. *
  58. * Behind the scenes, SDL will use newer, efficient APIs on platforms that
  59. * support them: Linux's io_uring and Windows 11's IoRing, for example. If
  60. * those technologies aren't available, SDL will offload the work to a thread
  61. * pool that will manage otherwise-synchronous loads without blocking the app.
  62. *
  63. * ## Best Practices
  64. *
  65. * Simple non-blocking I/O--for an app that just wants to pick up data
  66. * whenever it's ready without losing framerate waiting on disks to spin--can
  67. * use whatever pattern works well for the program. In this case, simply call
  68. * SDL_ReadAsyncIO, or maybe SDL_LoadFileAsync, as needed. Once a frame, call
  69. * SDL_GetAsyncIOResult to check for any completed tasks and deal with the
  70. * data as it arrives.
  71. *
  72. * If two separate pieces of the same program need their own I/O, it is legal
  73. * for each to create their own queue. This will prevent either piece from
  74. * accidentally consuming the other's completed tasks. Each queue does require
  75. * some amount of resources, but it is not an overwhelming cost. Do not make a
  76. * queue for each task, however. It is better to put many tasks into a single
  77. * queue. They will be reported in order of completion, not in the order they
  78. * were submitted, so it doesn't generally matter what order tasks are
  79. * started.
  80. *
  81. * One async I/O queue can be shared by multiple threads, or one thread can
  82. * have more than one queue, but the most efficient way--if ruthless
  83. * efficiency is the goal--is to have one queue per thread, with multiple
  84. * threads working in parallel, and attempt to keep each queue loaded with
  85. * tasks that are both started by and consumed by the same thread. On modern
  86. * platforms that can use newer interfaces, this can keep data flowing as
  87. * efficiently as possible all the way from storage hardware to the app, with
  88. * no contention between threads for access to the same queue.
  89. *
  90. * Written data is not guaranteed to make it to physical media by the time a
  91. * closing task is completed, unless SDL_CloseAsyncIO is called with its
  92. * `flush` parameter set to true, which is to say that a successful result
  93. * here can still result in lost data during an unfortunately-timed power
  94. * outage if not flushed. However, flushing will take longer and may be
  95. * unnecessary, depending on the app's needs.
  96. */
  97. #ifndef SDL_asyncio_h_
  98. #define SDL_asyncio_h_
  99. #include <SDL3/SDL_stdinc.h>
  100. #include <SDL3/SDL_begin_code.h>
  101. /* Set up for C function definitions, even when using C++ */
  102. #ifdef __cplusplus
  103. extern "C" {
  104. #endif
  105. /**
  106. * The asynchronous I/O operation structure.
  107. *
  108. * This operates as an opaque handle. One can then request read or write
  109. * operations on it.
  110. *
  111. * \since This struct is available since SDL 3.2.0.
  112. *
  113. * \sa SDL_AsyncIOFromFile
  114. */
  115. typedef struct SDL_AsyncIO SDL_AsyncIO;
  116. /**
  117. * Types of asynchronous I/O tasks.
  118. *
  119. * \since This enum is available since SDL 3.2.0.
  120. */
  121. typedef enum SDL_AsyncIOTaskType
  122. {
  123. SDL_ASYNCIO_TASK_READ, /**< A read operation. */
  124. SDL_ASYNCIO_TASK_WRITE, /**< A write operation. */
  125. SDL_ASYNCIO_TASK_CLOSE /**< A close operation. */
  126. } SDL_AsyncIOTaskType;
  127. /**
  128. * Possible outcomes of an asynchronous I/O task.
  129. *
  130. * \since This enum is available since SDL 3.2.0.
  131. */
  132. typedef enum SDL_AsyncIOResult
  133. {
  134. SDL_ASYNCIO_COMPLETE, /**< request was completed without error */
  135. SDL_ASYNCIO_FAILURE, /**< request failed for some reason; check SDL_GetError()! */
  136. SDL_ASYNCIO_CANCELED /**< request was canceled before completing. */
  137. } SDL_AsyncIOResult;
  138. /**
  139. * Information about a completed asynchronous I/O request.
  140. *
  141. * \since This struct is available since SDL 3.2.0.
  142. */
  143. typedef struct SDL_AsyncIOOutcome
  144. {
  145. SDL_AsyncIO *asyncio; /**< what generated this task. This pointer will be invalid if it was closed! */
  146. SDL_AsyncIOTaskType type; /**< What sort of task was this? Read, write, etc? */
  147. SDL_AsyncIOResult result; /**< the result of the work (success, failure, cancellation). */
  148. void *buffer; /**< buffer where data was read/written. */
  149. Uint64 offset; /**< offset in the SDL_AsyncIO where data was read/written. */
  150. Uint64 bytes_requested; /**< number of bytes the task was to read/write. */
  151. Uint64 bytes_transferred; /**< actual number of bytes that were read/written. */
  152. void *userdata; /**< pointer provided by the app when starting the task */
  153. } SDL_AsyncIOOutcome;
  154. /**
  155. * A queue of completed asynchronous I/O tasks.
  156. *
  157. * When starting an asynchronous operation, you specify a queue for the new
  158. * task. A queue can be asked later if any tasks in it have completed,
  159. * allowing an app to manage multiple pending tasks in one place, in whatever
  160. * order they complete.
  161. *
  162. * \since This struct is available since SDL 3.2.0.
  163. *
  164. * \sa SDL_CreateAsyncIOQueue
  165. * \sa SDL_ReadAsyncIO
  166. * \sa SDL_WriteAsyncIO
  167. * \sa SDL_GetAsyncIOResult
  168. * \sa SDL_WaitAsyncIOResult
  169. */
  170. typedef struct SDL_AsyncIOQueue SDL_AsyncIOQueue;
  171. /**
  172. * Use this function to create a new SDL_AsyncIO object for reading from
  173. * and/or writing to a named file.
  174. *
  175. * The `mode` string understands the following values:
  176. *
  177. * - "r": Open a file for reading only. It must exist.
  178. * - "w": Open a file for writing only. It will create missing files or
  179. * truncate existing ones.
  180. * - "r+": Open a file for update both reading and writing. The file must
  181. * exist.
  182. * - "w+": Create an empty file for both reading and writing. If a file with
  183. * the same name already exists its content is erased and the file is
  184. * treated as a new empty file.
  185. *
  186. * There is no "b" mode, as there is only "binary" style I/O, and no "a" mode
  187. * for appending, since you specify the position when starting a task.
  188. *
  189. * This function supports Unicode filenames, but they must be encoded in UTF-8
  190. * format, regardless of the underlying operating system.
  191. *
  192. * This call is _not_ asynchronous; it will open the file before returning,
  193. * under the assumption that doing so is generally a fast operation. Future
  194. * reads and writes to the opened file will be async, however.
  195. *
  196. * \param file a UTF-8 string representing the filename to open.
  197. * \param mode an ASCII string representing the mode to be used for opening
  198. * the file.
  199. * \returns a pointer to the SDL_AsyncIO structure that is created or NULL on
  200. * failure; call SDL_GetError() for more information.
  201. *
  202. * \since This function is available since SDL 3.2.0.
  203. *
  204. * \sa SDL_CloseAsyncIO
  205. * \sa SDL_ReadAsyncIO
  206. * \sa SDL_WriteAsyncIO
  207. */
  208. extern SDL_DECLSPEC SDL_AsyncIO * SDLCALL SDL_AsyncIOFromFile(const char *file, const char *mode);
  209. /**
  210. * Use this function to get the size of the data stream in an SDL_AsyncIO.
  211. *
  212. * This call is _not_ asynchronous; it assumes that obtaining this info is a
  213. * non-blocking operation in most reasonable cases.
  214. *
  215. * \param asyncio the SDL_AsyncIO to get the size of the data stream from.
  216. * \returns the size of the data stream in the SDL_IOStream on success or a
  217. * negative error code on failure; call SDL_GetError() for more
  218. * information.
  219. *
  220. * \threadsafety It is safe to call this function from any thread.
  221. *
  222. * \since This function is available since SDL 3.2.0.
  223. */
  224. extern SDL_DECLSPEC Sint64 SDLCALL SDL_GetAsyncIOSize(SDL_AsyncIO *asyncio);
  225. /**
  226. * Start an async read.
  227. *
  228. * This function reads up to `size` bytes from `offset` position in the data
  229. * source to the area pointed at by `ptr`. This function may read less bytes
  230. * than requested.
  231. *
  232. * This function returns as quickly as possible; it does not wait for the read
  233. * to complete. On a successful return, this work will continue in the
  234. * background. If the work begins, even failure is asynchronous: a failing
  235. * return value from this function only means the work couldn't start at all.
  236. *
  237. * `ptr` must remain available until the work is done, and may be accessed by
  238. * the system at any time until then. Do not allocate it on the stack, as this
  239. * might take longer than the life of the calling function to complete!
  240. *
  241. * An SDL_AsyncIOQueue must be specified. The newly-created task will be added
  242. * to it when it completes its work.
  243. *
  244. * \param asyncio a pointer to an SDL_AsyncIO structure.
  245. * \param ptr a pointer to a buffer to read data into.
  246. * \param offset the position to start reading in the data source.
  247. * \param size the number of bytes to read from the data source.
  248. * \param queue a queue to add the new SDL_AsyncIO to.
  249. * \param userdata an app-defined pointer that will be provided with the task
  250. * results.
  251. * \returns true on success or false on failure; call SDL_GetError() for more
  252. * information.
  253. *
  254. * \threadsafety It is safe to call this function from any thread.
  255. *
  256. * \since This function is available since SDL 3.2.0.
  257. *
  258. * \sa SDL_WriteAsyncIO
  259. * \sa SDL_CreateAsyncIOQueue
  260. */
  261. extern SDL_DECLSPEC bool SDLCALL SDL_ReadAsyncIO(SDL_AsyncIO *asyncio, void *ptr, Uint64 offset, Uint64 size, SDL_AsyncIOQueue *queue, void *userdata);
  262. /**
  263. * Start an async write.
  264. *
  265. * This function writes `size` bytes from `offset` position in the data source
  266. * to the area pointed at by `ptr`.
  267. *
  268. * This function returns as quickly as possible; it does not wait for the
  269. * write to complete. On a successful return, this work will continue in the
  270. * background. If the work begins, even failure is asynchronous: a failing
  271. * return value from this function only means the work couldn't start at all.
  272. *
  273. * `ptr` must remain available until the work is done, and may be accessed by
  274. * the system at any time until then. Do not allocate it on the stack, as this
  275. * might take longer than the life of the calling function to complete!
  276. *
  277. * An SDL_AsyncIOQueue must be specified. The newly-created task will be added
  278. * to it when it completes its work.
  279. *
  280. * \param asyncio a pointer to an SDL_AsyncIO structure.
  281. * \param ptr a pointer to a buffer to write data from.
  282. * \param offset the position to start writing to the data source.
  283. * \param size the number of bytes to write to the data source.
  284. * \param queue a queue to add the new SDL_AsyncIO to.
  285. * \param userdata an app-defined pointer that will be provided with the task
  286. * results.
  287. * \returns true on success or false on failure; call SDL_GetError() for more
  288. * information.
  289. *
  290. * \threadsafety It is safe to call this function from any thread.
  291. *
  292. * \since This function is available since SDL 3.2.0.
  293. *
  294. * \sa SDL_ReadAsyncIO
  295. * \sa SDL_CreateAsyncIOQueue
  296. */
  297. extern SDL_DECLSPEC bool SDLCALL SDL_WriteAsyncIO(SDL_AsyncIO *asyncio, void *ptr, Uint64 offset, Uint64 size, SDL_AsyncIOQueue *queue, void *userdata);
  298. /**
  299. * Close and free any allocated resources for an async I/O object.
  300. *
  301. * Closing a file is _also_ an asynchronous task! If a write failure were to
  302. * happen during the closing process, for example, the task results will
  303. * report it as usual.
  304. *
  305. * Closing a file that has been written to does not guarantee the data has
  306. * made it to physical media; it may remain in the operating system's file
  307. * cache, for later writing to disk. This means that a successfully-closed
  308. * file can be lost if the system crashes or loses power in this small window.
  309. * To prevent this, call this function with the `flush` parameter set to true.
  310. * This will make the operation take longer, and perhaps increase system load
  311. * in general, but a successful result guarantees that the data has made it to
  312. * physical storage. Don't use this for temporary files, caches, and
  313. * unimportant data, and definitely use it for crucial irreplaceable files,
  314. * like game saves.
  315. *
  316. * This function guarantees that the close will happen after any other pending
  317. * tasks to `asyncio`, so it's safe to open a file, start several operations,
  318. * close the file immediately, then check for all results later. This function
  319. * will not block until the tasks have completed.
  320. *
  321. * Once this function returns true, `asyncio` is no longer valid, regardless
  322. * of any future outcomes. Any completed tasks might still contain this
  323. * pointer in their SDL_AsyncIOOutcome data, in case the app was using this
  324. * value to track information, but it should not be used again.
  325. *
  326. * If this function returns false, the close wasn't started at all, and it's
  327. * safe to attempt to close again later.
  328. *
  329. * An SDL_AsyncIOQueue must be specified. The newly-created task will be added
  330. * to it when it completes its work.
  331. *
  332. * \param asyncio a pointer to an SDL_AsyncIO structure to close.
  333. * \param flush true if data should sync to disk before the task completes.
  334. * \param queue a queue to add the new SDL_AsyncIO to.
  335. * \param userdata an app-defined pointer that will be provided with the task
  336. * results.
  337. * \returns true on success or false on failure; call SDL_GetError() for more
  338. * information.
  339. *
  340. * \threadsafety It is safe to call this function from any thread, but two
  341. * threads should not attempt to close the same object.
  342. *
  343. * \since This function is available since SDL 3.2.0.
  344. */
  345. extern SDL_DECLSPEC bool SDLCALL SDL_CloseAsyncIO(SDL_AsyncIO *asyncio, bool flush, SDL_AsyncIOQueue *queue, void *userdata);
  346. /**
  347. * Create a task queue for tracking multiple I/O operations.
  348. *
  349. * Async I/O operations are assigned to a queue when started. The queue can be
  350. * checked for completed tasks thereafter.
  351. *
  352. * \returns a new task queue object or NULL if there was an error; call
  353. * SDL_GetError() for more information.
  354. *
  355. * \threadsafety It is safe to call this function from any thread.
  356. *
  357. * \since This function is available since SDL 3.2.0.
  358. *
  359. * \sa SDL_DestroyAsyncIOQueue
  360. * \sa SDL_GetAsyncIOResult
  361. * \sa SDL_WaitAsyncIOResult
  362. */
  363. extern SDL_DECLSPEC SDL_AsyncIOQueue * SDLCALL SDL_CreateAsyncIOQueue(void);
  364. /**
  365. * Destroy a previously-created async I/O task queue.
  366. *
  367. * If there are still tasks pending for this queue, this call will block until
  368. * those tasks are finished. All those tasks will be deallocated. Their
  369. * results will be lost to the app.
  370. *
  371. * Any pending reads from SDL_LoadFileAsync() that are still in this queue
  372. * will have their buffers deallocated by this function, to prevent a memory
  373. * leak.
  374. *
  375. * Once this function is called, the queue is no longer valid and should not
  376. * be used, including by other threads that might access it while destruction
  377. * is blocking on pending tasks.
  378. *
  379. * Do not destroy a queue that still has threads waiting on it through
  380. * SDL_WaitAsyncIOResult(). You can call SDL_SignalAsyncIOQueue() first to
  381. * unblock those threads, and take measures (such as SDL_WaitThread()) to make
  382. * sure they have finished their wait and won't wait on the queue again.
  383. *
  384. * \param queue the task queue to destroy.
  385. *
  386. * \threadsafety It is safe to call this function from any thread, so long as
  387. * no other thread is waiting on the queue with
  388. * SDL_WaitAsyncIOResult.
  389. *
  390. * \since This function is available since SDL 3.2.0.
  391. */
  392. extern SDL_DECLSPEC void SDLCALL SDL_DestroyAsyncIOQueue(SDL_AsyncIOQueue *queue);
  393. /**
  394. * Query an async I/O task queue for completed tasks.
  395. *
  396. * If a task assigned to this queue has finished, this will return true and
  397. * fill in `outcome` with the details of the task. If no task in the queue has
  398. * finished, this function will return false. This function does not block.
  399. *
  400. * If a task has completed, this function will free its resources and the task
  401. * pointer will no longer be valid. The task will be removed from the queue.
  402. *
  403. * It is safe for multiple threads to call this function on the same queue at
  404. * once; a completed task will only go to one of the threads.
  405. *
  406. * \param queue the async I/O task queue to query.
  407. * \param outcome details of a finished task will be written here. May not be
  408. * NULL.
  409. * \returns true if a task has completed, false otherwise.
  410. *
  411. * \threadsafety It is safe to call this function from any thread.
  412. *
  413. * \since This function is available since SDL 3.2.0.
  414. *
  415. * \sa SDL_WaitAsyncIOResult
  416. */
  417. extern SDL_DECLSPEC bool SDLCALL SDL_GetAsyncIOResult(SDL_AsyncIOQueue *queue, SDL_AsyncIOOutcome *outcome);
  418. /**
  419. * Block until an async I/O task queue has a completed task.
  420. *
  421. * This function puts the calling thread to sleep until there a task assigned
  422. * to the queue that has finished.
  423. *
  424. * If a task assigned to the queue has finished, this will return true and
  425. * fill in `outcome` with the details of the task. If no task in the queue has
  426. * finished, this function will return false.
  427. *
  428. * If a task has completed, this function will free its resources and the task
  429. * pointer will no longer be valid. The task will be removed from the queue.
  430. *
  431. * It is safe for multiple threads to call this function on the same queue at
  432. * once; a completed task will only go to one of the threads.
  433. *
  434. * Note that by the nature of various platforms, more than one waiting thread
  435. * may wake to handle a single task, but only one will obtain it, so
  436. * `timeoutMS` is a _maximum_ wait time, and this function may return false
  437. * sooner.
  438. *
  439. * This function may return false if there was a system error, the OS
  440. * inadvertently awoke multiple threads, or if SDL_SignalAsyncIOQueue() was
  441. * called to wake up all waiting threads without a finished task.
  442. *
  443. * A timeout can be used to specify a maximum wait time, but rather than
  444. * polling, it is possible to have a timeout of -1 to wait forever, and use
  445. * SDL_SignalAsyncIOQueue() to wake up the waiting threads later.
  446. *
  447. * \param queue the async I/O task queue to wait on.
  448. * \param outcome details of a finished task will be written here. May not be
  449. * NULL.
  450. * \param timeoutMS the maximum time to wait, in milliseconds, or -1 to wait
  451. * indefinitely.
  452. * \returns true if task has completed, false otherwise.
  453. *
  454. * \threadsafety It is safe to call this function from any thread.
  455. *
  456. * \since This function is available since SDL 3.2.0.
  457. *
  458. * \sa SDL_SignalAsyncIOQueue
  459. */
  460. extern SDL_DECLSPEC bool SDLCALL SDL_WaitAsyncIOResult(SDL_AsyncIOQueue *queue, SDL_AsyncIOOutcome *outcome, Sint32 timeoutMS);
  461. /**
  462. * Wake up any threads that are blocking in SDL_WaitAsyncIOResult().
  463. *
  464. * This will unblock any threads that are sleeping in a call to
  465. * SDL_WaitAsyncIOResult for the specified queue, and cause them to return
  466. * from that function.
  467. *
  468. * This can be useful when destroying a queue to make sure nothing is touching
  469. * it indefinitely. In this case, once this call completes, the caller should
  470. * take measures to make sure any previously-blocked threads have returned
  471. * from their wait and will not touch the queue again (perhaps by setting a
  472. * flag to tell the threads to terminate and then using SDL_WaitThread() to
  473. * make sure they've done so).
  474. *
  475. * \param queue the async I/O task queue to signal.
  476. *
  477. * \threadsafety It is safe to call this function from any thread.
  478. *
  479. * \since This function is available since SDL 3.2.0.
  480. *
  481. * \sa SDL_WaitAsyncIOResult
  482. */
  483. extern SDL_DECLSPEC void SDLCALL SDL_SignalAsyncIOQueue(SDL_AsyncIOQueue *queue);
  484. /**
  485. * Load all the data from a file path, asynchronously.
  486. *
  487. * This function returns as quickly as possible; it does not wait for the read
  488. * to complete. On a successful return, this work will continue in the
  489. * background. If the work begins, even failure is asynchronous: a failing
  490. * return value from this function only means the work couldn't start at all.
  491. *
  492. * The data is allocated with a zero byte at the end (null terminated) for
  493. * convenience. This extra byte is not included in SDL_AsyncIOOutcome's
  494. * bytes_transferred value.
  495. *
  496. * This function will allocate the buffer to contain the file. It must be
  497. * deallocated by calling SDL_free() on SDL_AsyncIOOutcome's buffer field
  498. * after completion.
  499. *
  500. * An SDL_AsyncIOQueue must be specified. The newly-created task will be added
  501. * to it when it completes its work.
  502. *
  503. * \param file the path to read all available data from.
  504. * \param queue a queue to add the new SDL_AsyncIO to.
  505. * \param userdata an app-defined pointer that will be provided with the task
  506. * results.
  507. * \returns true on success or false on failure; call SDL_GetError() for more
  508. * information.
  509. *
  510. * \since This function is available since SDL 3.2.0.
  511. *
  512. * \sa SDL_LoadFile_IO
  513. */
  514. extern SDL_DECLSPEC bool SDLCALL SDL_LoadFileAsync(const char *file, SDL_AsyncIOQueue *queue, void *userdata);
  515. /* Ends C function definitions when using C++ */
  516. #ifdef __cplusplus
  517. }
  518. #endif
  519. #include <SDL3/SDL_close_code.h>
  520. #endif /* SDL_asyncio_h_ */