switch to async system
[vg.git] / vg_mem.h
index 49d9e37e86b8af8d515a64a164d64873e6d6f59f..598bc83c352f3c7e382a0835cad459b0cbb2a113 100644 (file)
--- a/vg_mem.h
+++ b/vg_mem.h
@@ -88,7 +88,7 @@ struct vg_linear_allocator
 };
 #pragma pack(pop)
 
-VG_STATIC void vg_fatal_exit_loop( const char *error );
+VG_STATIC void vg_fatal_error( const char *fmt, ... );
 VG_STATIC void vg_error(const char *fmt, ...);
 VG_STATIC void vg_info(const char *fmt, ...);
 
@@ -127,20 +127,19 @@ VG_STATIC void *vg_linear_alloc( void *buffer, u32 size )
 #else
    if( ((u64)buffer) % 8 ){
 #endif
-      vg_error( "buffer: %p\n", buffer );
-      vg_fatal_exit_loop( "unaligned buffer" );
+      vg_fatal_error( "unaligned buffer (%p)", buffer );
    }
 
    vg_linear_allocator *alloc = vg_linear_header( buffer );
 
    if( (alloc->cur + size) > alloc->size ){
-      vg_error( "%u + %u > %u\n", alloc->cur, size, alloc->size );
-      vg_fatal_exit_loop( "linear allocator overflow" );
+      vg_fatal_error( "linear allocator overflow (%u + %u > %u)\n", 
+                        alloc->cur, size, alloc->size );
    }
 
    if( alloc->flags & VG_MEMORY_SYSTEM )
       if( (alloc->allocation_count + 1) > VG_MAX_ALLOCATIONS )
-         vg_fatal_exit_loop( "Max linear allocations reached" );
+         vg_fatal_error( "Max linear allocations reached" );
 
    void *data;
 
@@ -157,7 +156,7 @@ VG_STATIC void *vg_linear_alloc( void *buffer, u32 size )
 
    u8 *bytes = data;
    for( u32 i=0; i<size; i++ ){
-      bytes[i] = 0xae;
+      bytes[i] = 0xfe;
    }
 
    alloc->allocation_count ++;
@@ -170,7 +169,7 @@ VG_STATIC void *vg_linear_alloc( void *buffer, u32 size )
 #else
    if( ((u64)data) % 8 ){
 #endif
-      vg_fatal_exit_loop( "unaligned" );
+      vg_fatal_error( "unaligned" );
    }
 
    return data;
@@ -189,10 +188,10 @@ VG_STATIC void *vg_linear_resize( void *buffer, void *data, u32 newsize )
    }
 
    if( alloc->last_alloc != data )
-      vg_fatal_exit_loop( "This block has been fixed!" );
+      vg_fatal_error( "This block has been fixed!" );
 
    if( (alloc->cur - alloc->last_alloc_size + newsize) > alloc->size )
-      vg_fatal_exit_loop( "Cannot resize, overflow" );
+      vg_fatal_error( "Cannot resize, overflow" );
 
    alloc->cur -= alloc->last_alloc_size;
    alloc->cur += newsize;
@@ -201,7 +200,7 @@ VG_STATIC void *vg_linear_resize( void *buffer, void *data, u32 newsize )
    if( vg_mem.use_libc_malloc && (alloc->flags & VG_MEMORY_SYSTEM) ){
       data = realloc( data, newsize );
       if( !data )
-         vg_fatal_exit_loop( "realloc failed" );
+         vg_fatal_error( "realloc failed" );
 
       alloc->alloc_table[ alloc->allocation_count-1 ].data = data;
       alloc->last_alloc = data;
@@ -218,12 +217,12 @@ VG_STATIC void vg_linear_del( void *buffer, void *data )
    vg_linear_allocator *alloc = vg_linear_header( buffer );
 
    if( alloc->last_alloc != data )
-      vg_fatal_exit_loop( "This block has been fixed!" );
+      vg_fatal_error( "This block has been fixed!" );
 
    if( vg_mem.use_libc_malloc && (alloc->flags & VG_MEMORY_SYSTEM) ){
       vg_allocation_meta *meta = &alloc->alloc_table[alloc->allocation_count-1];
       if( meta->type == k_allocation_type_linear )
-         vg_fatal_exit_loop( "Cannot free a linear allocator in this conext" );
+         vg_fatal_error( "Cannot free a linear allocator in this conext" );
 
       free( data );
    }
@@ -244,7 +243,7 @@ VG_STATIC void *vg_linear_extend( void *buffer, void *data, u32 extra )
    vg_linear_allocator *alloc = vg_linear_header( buffer );
 
    if( alloc->last_alloc != data )
-      vg_fatal_exit_loop( "This block has been fixed!" );
+      vg_fatal_error( "This block has been fixed!" );
 
    u32 new_size = alloc->last_alloc_size + extra;
    return vg_linear_resize( buffer, data, new_size );
@@ -314,13 +313,13 @@ VG_STATIC void *vg_create_linear_allocator( void *lin_alloc, u32 size,
       vg_linear_allocator *alloc = vg_linear_header( lin_alloc );
 
       if( alloc->cur + block_size > alloc->size )
-         vg_fatal_exit_loop( "Out of memory" );
+         vg_fatal_error( "Out of memory" );
 
       if( alloc->allocation_count + 1 > VG_MAX_ALLOCATIONS )
-         vg_fatal_exit_loop( "Max allocations in linear allocator" );
+         vg_fatal_error( "Max allocations in linear allocator" );
 
       if( (flags && VG_MEMORY_SYSTEM) && (alloc->flags & VG_MEMORY_REALTIME) )
-         vg_fatal_exit_loop( "Cannot declare realtime allocator inside systems"
+         vg_fatal_error( "Cannot declare realtime allocator inside systems"
                              " allocator" );
 
       if( vg_mem.use_libc_malloc ){