commit 6df8b214ee16b78237bfa0df82da7a3b937d6842 parent f99d1fb0d06de8ead375c15efe7a5b3f8659ee17 Author: Michael Savage <mikejsavage@gmail.com> Date: Wed Oct 12 19:50:41 +0300 Const madness Diffstat:
intrinsics.h | | | 10 | +++++----- |
work_queue.cc | | | 2 | +- |
work_queue.h | | | 14 | ++++++-------- |
diff --git a/intrinsics.h b/intrinsics.h @@ -92,8 +92,8 @@ T clamp11( T x ) { #undef assert #endif -inline void mike_assert( const bool predicate, const char * const message ) { - if( !( predicate ) ) { +inline void mike_assert( const bool predicate, const char * message ) { + if( !predicate ) { puts( message ); int err = errno; printf( "errno(%d): %s\n", err, strerror( err ) ); @@ -118,8 +118,8 @@ inline void mike_assert( const bool predicate, const char * const message ) { #define assert( predicate ) mike_assert( predicate, "\x1b[1;31massertion failed at " __FILE__ " line " STRINGIFY( __LINE__ ) ": \x1b[0;1m" #predicate "\x1b[0m" ) // TODO: this sucks -inline u8 * file_get_contents( const char * const path, size_t * const out_len = NULL ) { - FILE * const file = fopen( path, "rb" ); +inline u8 * file_get_contents( const char * path, size_t * out_len = NULL ) { + FILE * file = fopen( path, "rb" ); assert( file != NULL ); fseek( file, 0, SEEK_END ); @@ -127,7 +127,7 @@ inline u8 * file_get_contents( const char * const path, size_t * const out_len = fseek( file, 0, SEEK_SET ); // TODO: oh-no-verflow - u8 * const contents = ( u8 * const ) malloc( len + 1 ); + u8 * contents = ( u8 * const ) malloc( len + 1 ); size_t bytes_read = fread( contents, 1, len, file ); contents[ len ] = '\0'; assert( bytes_read == len ); diff --git a/work_queue.cc b/work_queue.cc @@ -81,7 +81,7 @@ void workqueue_init( WorkQueue * queue, MemoryArena * arena, u32 num_threads ) { } } -void workqueue_enqueue( WorkQueue * queue, WorkQueueCallback * callback, void * data ) { +void workqueue_enqueue( WorkQueue * queue, WorkQueueCallback * callback, const void * data ) { u32 tail = fetch_add_release( &queue->tail, 1 ); assert( tail - load_acquire( &queue->head ) < array_count( queue->jobs ) - 1 ); diff --git a/work_queue.h b/work_queue.h @@ -6,12 +6,12 @@ #include "platform_semaphore.h" #include "memory_arena.h" -#define WORK_QUEUE_CALLBACK( name ) void name( void * const data, MemoryArena * const arena ) +#define WORK_QUEUE_CALLBACK( name ) void name( const void * data, MemoryArena * arena ) typedef WORK_QUEUE_CALLBACK( WorkQueueCallback ); struct Job { WorkQueueCallback * callback; - void * data; + const void * data; }; struct WorkQueue { @@ -19,16 +19,14 @@ struct WorkQueue { Semaphore sem; - // using head/length means we need to an atomic pair which is a pain - atomic_u32 head; - atomic_u32 tail; + atomic_u32 head, tail; u32 num_threads; MemoryArena * arenas; }; -void workqueue_init( WorkQueue * const queue, MemoryArena * const arena, const u32 num_threads ); -void workqueue_enqueue( WorkQueue * const queue, WorkQueueCallback * const callback, void * const data ); -void workqueue_exhaust( WorkQueue * const queue ); +void workqueue_init( WorkQueue * queue, MemoryArena * arena, u32 num_threads ); +void workqueue_enqueue( WorkQueue * queue, WorkQueueCallback * callback, const void * data ); +void workqueue_exhaust( WorkQueue * queue ); #endif // _WORK_QUEUE_H_