medfall

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

commit 430387c24815c59512043d0b8f8d852ca76f0b92
parent d5d0c14cec7465765382b1de4cf8af05f9d96dfd
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Wed Oct 12 19:52:15 +0300

Add a compile time switch to disable worker threads

Diffstat:
work_queue.cc | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/work_queue.cc b/work_queue.cc @@ -59,7 +59,6 @@ void workqueue_init( WorkQueue * queue, MemoryArena * arena, u32 num_threads ) { queue->arenas[ i ] = memarena_push_arena( arena, megabytes( 16 ) ); } - // TODO: if we comment this out we can get rid of the wait at the bottom MEMARENA_SCOPED_CHECKPOINT( arena ); ThreadInfo * infos = memarena_push_many( arena, ThreadInfo, num_threads ); @@ -75,13 +74,15 @@ void workqueue_init( WorkQueue * queue, MemoryArena * arena, u32 num_threads ) { // wait until all threads have a local copy of ThreadInfo // TODO: do this properly - // TODO: do we really need to do this? while( load_acquire( &started_threads ) < num_threads ) { continue; } } void workqueue_enqueue( WorkQueue * queue, WorkQueueCallback * callback, const void * data ) { +#if DISABLE_THREADS + callback( data, &queue->arenas[ 0 ] ); +#else u32 tail = fetch_add_release( &queue->tail, 1 ); assert( tail - load_acquire( &queue->head ) < array_count( queue->jobs ) - 1 ); @@ -90,6 +91,7 @@ void workqueue_enqueue( WorkQueue * queue, WorkQueueCallback * callback, const v queue->jobs[ tail % array_count( queue->jobs ) ] = job; semaphore_signal( &queue->sem ); +#endif } void workqueue_exhaust( WorkQueue * queue ) {