SDL_asyncio.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2026 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. * \threadsafety It is safe to call this function from any thread.
  203. *
  204. * \since This function is available since SDL 3.2.0.
  205. *
  206. * \sa SDL_CloseAsyncIO
  207. * \sa SDL_ReadAsyncIO
  208. * \sa SDL_WriteAsyncIO
  209. */
  210. extern SDL_DECLSPEC SDL_AsyncIO * SDLCALL SDL_AsyncIOFromFile(const char *file, const char *mode);
  211. /**
  212. * Use this function to get the size of the data stream in an SDL_AsyncIO.
  213. *
  214. * This call is _not_ asynchronous; it assumes that obtaining this info is a
  215. * non-blocking operation in most reasonable cases.
  216. *
  217. * \param asyncio the SDL_AsyncIO to get the size of the data stream from.
  218. * \returns the size of the data stream in the SDL_IOStream on success or a
  219. * negative error code on failure; call SDL_GetError() for more
  220. * information.
  221. *
  222. * \threadsafety It is safe to call this function from any thread.
  223. *
  224. * \since This function is available since SDL 3.2.0.
  225. */
  226. extern SDL_DECLSPEC Sint64 SDLCALL SDL_GetAsyncIOSize(SDL_AsyncIO *asyncio);
  227. /**
  228. * Start an async read.
  229. *
  230. * This function reads up to `size` bytes from `offset` position in the data
  231. * source to the area pointed at by `ptr`. This function may read less bytes
  232. * than requested.
  233. *
  234. * This function returns as quickly as possible; it does not wait for the read
  235. * to complete. On a successful return, this work will continue in the
  236. * background. If the work begins, even failure is asynchronous: a failing
  237. * return value from this function only means the work couldn't start at all.
  238. *
  239. * `ptr` must remain available until the work is done, and may be accessed by
  240. * the system at any time until then. Do not allocate it on the stack, as this
  241. * might take longer than the life of the calling function to complete!
  242. *
  243. * An SDL_AsyncIOQueue must be specified. The newly-created task will be added
  244. * to it when it completes its work.
  245. *
  246. * \param asyncio a pointer to an SDL_AsyncIO structure.
  247. * \param ptr a pointer to a buffer to read data into.
  248. * \param offset the position to start reading in the data source.
  249. * \param size the number of bytes to read from the data source.
  250. * \param queue a queue to add the new SDL_AsyncIO to.
  251. * \param userdata an app-defined pointer that will be provided with the task
  252. * results.
  253. * \returns true on success or false on failure; call SDL_GetError() for more
  254. * information.
  255. *
  256. * \threadsafety It is safe to call this function from any thread.
  257. *
  258. * \since This function is available since SDL 3.2.0.
  259. *
  260. * \sa SDL_WriteAsyncIO
  261. * \sa SDL_CreateAsyncIOQueue
  262. */
  263. extern SDL_DECLSPEC bool SDLCALL SDL_ReadAsyncIO(SDL_AsyncIO *asyncio, void *ptr, Uint64 offset, Uint64 size, SDL_AsyncIOQueue *queue, void *userdata);
  264. /**
  265. * Start an async write.
  266. *
  267. * This function writes `size` bytes from `offset` position in the data source
  268. * to the area pointed at by `ptr`.
  269. *
  270. * This function returns as quickly as possible; it does not wait for the
  271. * write to complete. On a successful return, this work will continue in the
  272. * background. If the work begins, even failure is asynchronous: a failing
  273. * return value from this function only means the work couldn't start at all.
  274. *
  275. * `ptr` must remain available until the work is done, and may be accessed by
  276. * the system at any time until then. Do not allocate it on the stack, as this
  277. * might take longer than the life of the calling function to complete!
  278. *
  279. * An SDL_AsyncIOQueue must be specified. The newly-created task will be added
  280. * to it when it completes its work.
  281. *
  282. * \param asyncio a pointer to an SDL_AsyncIO structure.
  283. * \param ptr a pointer to a buffer to write data from.
  284. * \param offset the position to start writing to the data source.
  285. * \param size the number of bytes to write to the data source.
  286. * \param queue a queue to add the new SDL_AsyncIO to.
  287. * \param userdata an app-defined pointer that will be provided with the task
  288. * results.
  289. * \returns true on success or false on failure; call SDL_GetError() for more
  290. * information.
  291. *
  292. * \threadsafety It is safe to call this function from any thread.
  293. *
  294. * \since This function is available since SDL 3.2.0.
  295. *
  296. * \sa SDL_ReadAsyncIO
  297. * \sa SDL_CreateAsyncIOQueue
  298. */
  299. extern SDL_DECLSPEC bool SDLCALL SDL_WriteAsyncIO(SDL_AsyncIO *asyncio, void *ptr, Uint64 offset, Uint64 size, SDL_AsyncIOQueue *queue, void *userdata);
  300. /**
  301. * Close and free any allocated resources for an async I/O object.
  302. *
  303. * Closing a file is _also_ an asynchronous task! If a write failure were to
  304. * happen during the closing process, for example, the task results will
  305. * report it as usual.
  306. *
  307. * Closing a file that has been written to does not guarantee the data has
  308. * made it to physical media; it may remain in the operating system's file
  309. * cache, for later writing to disk. This means that a successfully-closed
  310. * file can be lost if the system crashes or loses power in this small window.
  311. * To prevent this, call this function with the `flush` parameter set to true.
  312. * This will make the operation take longer, and perhaps increase system load
  313. * in general, but a successful result guarantees that the data has made it to
  314. * physical storage. Don't use this for temporary files, caches, and
  315. * unimportant data, and definitely use it for crucial irreplaceable files,
  316. * like game saves.
  317. *
  318. * This function guarantees that the close will happen after any other pending
  319. * tasks to `asyncio`, so it's safe to open a file, start several operations,
  320. * close the file immediately, then check for all results later. This function
  321. * will not block until the tasks have completed.
  322. *
  323. * Once this function returns true, `asyncio` is no longer valid, regardless
  324. * of any future outcomes. Any completed tasks might still contain this
  325. * pointer in their SDL_AsyncIOOutcome data, in case the app was using this
  326. * value to track information, but it should not be used again.
  327. *
  328. * If this function returns false, the close wasn't started at all, and it's
  329. * safe to attempt to close again later.
  330. *
  331. * An SDL_AsyncIOQueue must be specified. The newly-created task will be added
  332. * to it when it completes its work.
  333. *
  334. * \param asyncio a pointer to an SDL_AsyncIO structure to close.
  335. * \param flush true if data should sync to disk before the task completes.
  336. * \param queue a queue to add the new SDL_AsyncIO to.
  337. * \param userdata an app-defined pointer that will be provided with the task
  338. * results.
  339. * \returns true on success or false on failure; call SDL_GetError() for more
  340. * information.
  341. *
  342. * \threadsafety It is safe to call this function from any thread, but two
  343. * threads should not attempt to close the same object.
  344. *
  345. * \since This function is available since SDL 3.2.0.
  346. */
  347. extern SDL_DECLSPEC bool SDLCALL SDL_CloseAsyncIO(SDL_AsyncIO *asyncio, bool flush, SDL_AsyncIOQueue *queue, void *userdata);
  348. /**
  349. * Create a task queue for tracking multiple I/O operations.
  350. *
  351. * Async I/O operations are assigned to a queue when started. The queue can be
  352. * checked for completed tasks thereafter.
  353. *
  354. * \returns a new task queue object or NULL if there was an error; call
  355. * SDL_GetError() for more information.
  356. *
  357. * \threadsafety It is safe to call this function from any thread.
  358. *
  359. * \since This function is available since SDL 3.2.0.
  360. *
  361. * \sa SDL_DestroyAsyncIOQueue
  362. * \sa SDL_GetAsyncIOResult
  363. * \sa SDL_WaitAsyncIOResult
  364. */
  365. extern SDL_DECLSPEC SDL_AsyncIOQueue * SDLCALL SDL_CreateAsyncIOQueue(void);
  366. /**
  367. * Destroy a previously-created async I/O task queue.
  368. *
  369. * If there are still tasks pending for this queue, this call will block until
  370. * those tasks are finished. All those tasks will be deallocated. Their
  371. * results will be lost to the app.
  372. *
  373. * Any pending reads from SDL_LoadFileAsync() that are still in this queue
  374. * will have their buffers deallocated by this function, to prevent a memory
  375. * leak.
  376. *
  377. * Once this function is called, the queue is no longer valid and should not
  378. * be used, including by other threads that might access it while destruction
  379. * is blocking on pending tasks.
  380. *
  381. * Do not destroy a queue that still has threads waiting on it through
  382. * SDL_WaitAsyncIOResult(). You can call SDL_SignalAsyncIOQueue() first to
  383. * unblock those threads, and take measures (such as SDL_WaitThread()) to make
  384. * sure they have finished their wait and won't wait on the queue again.
  385. *
  386. * \param queue the task queue to destroy.
  387. *
  388. * \threadsafety It is safe to call this function from any thread, so long as
  389. * no other thread is waiting on the queue with
  390. * SDL_WaitAsyncIOResult.
  391. *
  392. * \since This function is available since SDL 3.2.0.
  393. */
  394. extern SDL_DECLSPEC void SDLCALL SDL_DestroyAsyncIOQueue(SDL_AsyncIOQueue *queue);
  395. /**
  396. * Query an async I/O task queue for completed tasks.
  397. *
  398. * If a task assigned to this queue has finished, this will return true and
  399. * fill in `outcome` with the details of the task. If no task in the queue has
  400. * finished, this function will return false. This function does not block.
  401. *
  402. * If a task has completed, this function will free its resources and the task
  403. * pointer will no longer be valid. The task will be removed from the queue.
  404. *
  405. * It is safe for multiple threads to call this function on the same queue at
  406. * once; a completed task will only go to one of the threads.
  407. *
  408. * \param queue the async I/O task queue to query.
  409. * \param outcome details of a finished task will be written here. May not be
  410. * NULL.
  411. * \returns true if a task has completed, false otherwise.
  412. *
  413. * \threadsafety It is safe to call this function from any thread.
  414. *
  415. * \since This function is available since SDL 3.2.0.
  416. *
  417. * \sa SDL_WaitAsyncIOResult
  418. */
  419. extern SDL_DECLSPEC bool SDLCALL SDL_GetAsyncIOResult(SDL_AsyncIOQueue *queue, SDL_AsyncIOOutcome *outcome);
  420. /**
  421. * Block until an async I/O task queue has a completed task.
  422. *
  423. * This function puts the calling thread to sleep until there a task assigned
  424. * to the queue that has finished.
  425. *
  426. * If a task assigned to the queue has finished, this will return true and
  427. * fill in `outcome` with the details of the task. If no task in the queue has
  428. * finished, this function will return false.
  429. *
  430. * If a task has completed, this function will free its resources and the task
  431. * pointer will no longer be valid. The task will be removed from the queue.
  432. *
  433. * It is safe for multiple threads to call this function on the same queue at
  434. * once; a completed task will only go to one of the threads.
  435. *
  436. * Note that by the nature of various platforms, more than one waiting thread
  437. * may wake to handle a single task, but only one will obtain it, so
  438. * `timeoutMS` is a _maximum_ wait time, and this function may return false
  439. * sooner.
  440. *
  441. * This function may return false if there was a system error, the OS
  442. * inadvertently awoke multiple threads, or if SDL_SignalAsyncIOQueue() was
  443. * called to wake up all waiting threads without a finished task.
  444. *
  445. * A timeout can be used to specify a maximum wait time, but rather than
  446. * polling, it is possible to have a timeout of -1 to wait forever, and use
  447. * SDL_SignalAsyncIOQueue() to wake up the waiting threads later.
  448. *
  449. * \param queue the async I/O task queue to wait on.
  450. * \param outcome details of a finished task will be written here. May not be
  451. * NULL.
  452. * \param timeoutMS the maximum time to wait, in milliseconds, or -1 to wait
  453. * indefinitely.
  454. * \returns true if task has completed, false otherwise.
  455. *
  456. * \threadsafety It is safe to call this function from any thread.
  457. *
  458. * \since This function is available since SDL 3.2.0.
  459. *
  460. * \sa SDL_SignalAsyncIOQueue
  461. */
  462. extern SDL_DECLSPEC bool SDLCALL SDL_WaitAsyncIOResult(SDL_AsyncIOQueue *queue, SDL_AsyncIOOutcome *outcome, Sint32 timeoutMS);
  463. /**
  464. * Wake up any threads that are blocking in SDL_WaitAsyncIOResult().
  465. *
  466. * This will unblock any threads that are sleeping in a call to
  467. * SDL_WaitAsyncIOResult for the specified queue, and cause them to return
  468. * from that function.
  469. *
  470. * This can be useful when destroying a queue to make sure nothing is touching
  471. * it indefinitely. In this case, once this call completes, the caller should
  472. * take measures to make sure any previously-blocked threads have returned
  473. * from their wait and will not touch the queue again (perhaps by setting a
  474. * flag to tell the threads to terminate and then using SDL_WaitThread() to
  475. * make sure they've done so).
  476. *
  477. * \param queue the async I/O task queue to signal.
  478. *
  479. * \threadsafety It is safe to call this function from any thread.
  480. *
  481. * \since This function is available since SDL 3.2.0.
  482. *
  483. * \sa SDL_WaitAsyncIOResult
  484. */
  485. extern SDL_DECLSPEC void SDLCALL SDL_SignalAsyncIOQueue(SDL_AsyncIOQueue *queue);
  486. /**
  487. * Load all the data from a file path, asynchronously.
  488. *
  489. * This function returns as quickly as possible; it does not wait for the read
  490. * to complete. On a successful return, this work will continue in the
  491. * background. If the work begins, even failure is asynchronous: a failing
  492. * return value from this function only means the work couldn't start at all.
  493. *
  494. * The data is allocated with a zero byte at the end (null terminated) for
  495. * convenience. This extra byte is not included in SDL_AsyncIOOutcome's
  496. * bytes_transferred value.
  497. *
  498. * This function will allocate the buffer to contain the file. It must be
  499. * deallocated by calling SDL_free() on SDL_AsyncIOOutcome's buffer field
  500. * after completion.
  501. *
  502. * An SDL_AsyncIOQueue must be specified. The newly-created task will be added
  503. * to it when it completes its work.
  504. *
  505. * \param file the path to read all available data from.
  506. * \param queue a queue to add the new SDL_AsyncIO to.
  507. * \param userdata an app-defined pointer that will be provided with the task
  508. * results.
  509. * \returns true on success or false on failure; call SDL_GetError() for more
  510. * information.
  511. *
  512. * \threadsafety It is safe to call this function from any thread.
  513. *
  514. * \since This function is available since SDL 3.2.0.
  515. *
  516. * \sa SDL_LoadFile_IO
  517. */
  518. extern SDL_DECLSPEC bool SDLCALL SDL_LoadFileAsync(const char *file, SDL_AsyncIOQueue *queue, void *userdata);
  519. /* Ends C function definitions when using C++ */
  520. #ifdef __cplusplus
  521. }
  522. #endif
  523. #include <SDL3/SDL_close_code.h>
  524. #endif /* SDL_asyncio_h_ */