medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 00e3d8c8e71e418e030a012b2236d0c4ba5ed219
parent 7f65e570b65f24f2e952cfd9d6c2b5d070dd7084
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat Mar 11 10:32:22 +0200

COUNTER_NAME and LINE_NAME

Diffstat:
intrinsics.h | 12+++++++-----
memory_arena.h | 2+-
platform_mutex.h | 2+-
profiler.h | 12++++++------
4 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/intrinsics.h b/intrinsics.h @@ -52,9 +52,6 @@ char ( &ArrayCountObj( const T ( & )[ N ] ) )[ N ]; #define megabytes( mb ) ( kilobytes( mb ) * size_t( 1024 ) ) #define gigabytes( gb ) ( megabytes( gb ) * size_t( 1024 ) ) -#define CACHE_LINE_SIZE 64 -#define CACHE_LINE_PADDING u8 CONCAT( cache_line_spacing, __COUNTER__ )[ CACHE_LINE_SIZE ] - template< typename T > inline T min( T a, T b ) { return a < b ? a : b; @@ -124,13 +121,18 @@ inline void assert_impl( const bool predicate, const char * message ) { #define CONCAT_HELPER( a, b ) a##b #define CONCAT( a, b ) CONCAT_HELPER( a, b ) +#define COUNTER_NAME( x ) CONCAT( x, __COUNTER__ ) +#define LINE_NAME( x ) CONCAT( x, __LINE__ ) + +#define CACHE_LINE_SIZE 64 +#define CACHE_LINE_PADDING u8 COUNTER_NAME( cache_line_spacing )[ CACHE_LINE_SIZE ] #define ASSERT( predicate ) assert_impl( predicate, "\x1b[1;31massertion failed at " __FILE__ " line " STRINGIFY( __LINE__ ) ": \x1b[0;1m" #predicate "\x1b[0m" ) #if COMPILER_MSVC || __cplusplus >= 201103L #define STATIC_ASSERT( p ) static_assert( p, #p ) #elif __cplusplus < 201103L -#define STATIC_ASSERT( p ) static int CONCAT( STATIC_ASSERT, __COUNTER__ )[ int( p ) - 1 ] +#define STATIC_ASSERT( p ) static int COUNTER_NAME( STATIC_ASSERT_ )[ int( p ) - 1 ] #endif #if !PLATFORM_RELACY @@ -150,7 +152,7 @@ template< typename F > inline ScopeExit< F > MakeScopeExit( F f ) { return ScopeExit< F >( f ); }; -#define SCOPE_EXIT( code ) auto CONCAT( SCOPE_EXIT_, __COUNTER__ ) = MakeScopeExit( [=]() { code; } ) +#define SCOPE_EXIT( code ) auto COUNTER_NAME( SCOPE_EXIT_ ) = MakeScopeExit( [=]() { code; } ) template< typename S, typename T > struct SameType { diff --git a/memory_arena.h b/memory_arena.h @@ -42,4 +42,4 @@ void memarena_clear( MemoryArena * arena ); MemoryArenaCheckpoint memarena_checkpoint( MemoryArena * arena ); void memarena_restore( MemoryArena * arena, MemoryArenaCheckpoint * cp ); -#define MEMARENA_SCOPED_CHECKPOINT( arena ) MemoryArenaAutoCheckpoint CONCAT( mem_cp, __COUNTER__ )( arena, memarena_checkpoint( arena ) ); +#define MEMARENA_SCOPED_CHECKPOINT( arena ) MemoryArenaAutoCheckpoint COUNTER_NAME( mem_cp )( arena, memarena_checkpoint( arena ) ); diff --git a/platform_mutex.h b/platform_mutex.h @@ -24,4 +24,4 @@ struct ScopedMutexLock { }; #define SCOPED_MUTEX_LOCK( mutex ) \ - ScopedMutexLock CONCAT( scoped_mtx, __COUNTER___ )( mutex ); + ScopedMutexLock COUNTER_NAME( scoped_mtx )( mutex ); diff --git a/profiler.h b/profiler.h @@ -18,10 +18,10 @@ struct ScopedTimer { }; #define PROFILE_BLOCK( fmt, ... ) \ - static u32 CONCAT( scoped_timer_idx, __LINE__ ) = profiler_new_timer( fmt, __FILE__, __LINE__ ); \ - char CONCAT( scoped_timer_name, __LINE__ )[ PROFILE_BLOCK_NAME_LENGTH ]; \ - snprintf( CONCAT( scoped_timer_name, __LINE__ ), PROFILE_BLOCK_NAME_LENGTH, fmt, ##__VA_ARGS__ ); \ - ScopedTimer CONCAT( scoped_timer, __LINE__ )( CONCAT( scoped_timer_idx, __LINE__ ), CONCAT( scoped_timer_name, __LINE__ ) ); + static u32 LINE_NAME( scoped_timer_idx ) = profiler_new_timer( fmt, __FILE__, __LINE__ ); \ + char LINE_NAME( scoped_timer_name )[ PROFILE_BLOCK_NAME_LENGTH ]; \ + snprintf( LINE_NAME( scoped_timer_name ), PROFILE_BLOCK_NAME_LENGTH, fmt, ##__VA_ARGS__ ); \ + ScopedTimer LINE_NAME( scoped_timer )( LINE_NAME( scoped_timer_idx ), LINE_NAME( scoped_timer_name ) ); #define PROFILE_FUNCTION() \ - static u32 CONCAT( scoped_timer_idx, __LINE__ ) = profiler_new_timer( __FUNCTION__, __FILE__, __LINE__ ); \ - ScopedTimer CONCAT( scoped_timer, __LINE__ )( CONCAT( scoped_timer_idx, __LINE__ ), __FUNCTION__ ); + static u32 LINE_NAME( scoped_timer_idx ) = profiler_new_timer( __FUNCTION__, __FILE__, __LINE__ ); \ + ScopedTimer LINE_NAME( scoped_timer )( LINE_NAME( scoped_timer_idx ), __FUNCTION__ );