bad char
[vg.git] / vg_async.h
1 /* Copyright (C) 2021-2024 Harry Godden (hgn) - All Rights Reserved
2 *
3 * primateves that you use when you need to run something from another thread
4 * back in the main loop of vg, at the start of each frame
5 */
6
7 #pragma once
8 #include "vg_engine.h"
9
10 static void vg_assert_thread( enum vg_thread_purpose required );
11
12 typedef struct vg_async_item vg_async_item;
13 struct vg_async_item{
14 vg_async_item *next;
15
16 void *payload;
17 u32 size;
18
19 void (*fn_runner)( void *payload, u32 size );
20 };
21
22 struct vg_async
23 {
24 void *buffer;
25
26 vg_async_item *start, *end;
27
28 SDL_sem *sem_wait_for_flush;
29 SDL_SpinLock sl_index;
30 }
31 extern vg_async;
32
33 /* TODO: Docu */
34
35 void vg_async_call( void (*runner)( void *payload, u32 size ),
36 void *payload, u32 size );
37 void vg_run_async_checked(void);
38 void vg_async_init(void);
39
40 vg_async_item *vg_async_alloc( u32 size );
41 /*
42 * Mark the call as being filled and ready to go
43 */
44 void vg_async_dispatch( vg_async_item *item,
45 void (*runner)( void *payload, u32 size ) );
46
47 /*
48 * Wait until the current stack of async calls is completely flushed out
49 */
50 void vg_async_stall(void);