-static vg_async;
-
-static enum vg_thread_purpose vg_thread_purpose(void);
-static enum engine_status _vg_engine_status(void);
-
-/*
- * Allocate an asynchronous call with a bit of memory
- */
-static vg_async_item *vg_async_alloc( u32 size )
-{
- /* ditch out here if engine crashed. this serves as the 'quit checking' */
- if( _vg_engine_status() == k_engine_status_crashed ){
- assert( vg_thread_purpose() == k_thread_purpose_loader );
- longjmp( vg.env_loader_exit, 1 );
- }
-
- SDL_AtomicLock( &vg_async.sl_index );
-
- u32 total_allocation = vg_align8(size) + vg_align8(sizeof(vg_async_item)),
- remaining = vg_linear_remaining( vg_async.buffer ),
- capacity = vg_linear_get_capacity( vg_async.buffer );
-
- if( total_allocation > capacity ){
- SDL_AtomicUnlock( &vg_async.sl_index );
- vg_error( "Requested: %umb. Buffer size: %umb\n",
- (total_allocation/1024)/1024,
- (capacity/1024)/1024 );
-
- vg_fatal_error( "async alloc invalid size\n" );
- }
-
- if( total_allocation > remaining ){
- SDL_AtomicUnlock( &vg_async.sl_index );
- SDL_SemWait( vg_async.sem_wait_for_flush );
- SDL_AtomicLock( &vg_async.sl_index );