diff --git a/mandelbrot-visualizer.c b/mandelbrot-visualizer.c index 18a854a..4b2ae47 100644 --- a/mandelbrot-visualizer.c +++ b/mandelbrot-visualizer.c @@ -31,7 +31,7 @@ struct threadInfo { /* * Concurrency model explained: * One main thread, along with many workers in a thread pool, who split the work of - * rendering roughly equally. The writers don't do any work until the pixel map which they + * rendering roughly equally. The workers don't do any work until the pixel map which they * are meant to work on is marked as available, and they are all singalled to start * drawing. * @@ -84,7 +84,7 @@ void color_lookup(int *r, int *g, int *b, double mu); // worker code gboolean queue_redraw_plane(void *arg); -void *writer_thread(void *arg) +void *worker_thread(void *arg) { struct threadInfo *info = arg; while (true) { @@ -121,7 +121,7 @@ void draw_mandelbrot(struct threadInfo *info) pthread_mutex_unlock(&pixmapMutex); return; // after this, the thread will again enter the - // loop in the writer_thread function, and + // loop in the worker_thread function, and // enter a wait state } pthread_mutex_unlock(&pixmapMutex); @@ -138,13 +138,13 @@ void draw_mandelbrot(struct threadInfo *info) } pthread_mutex_lock(&pixmapMutex); info->complete = true; - bool allWritersComplete = true; + bool allWorkersComplete = true; for (int32_t i = 0; i < thread_count; i++) { if (!threads[i].complete) { - allWritersComplete = false; + allWorkersComplete = false; } } - if (allWritersComplete) { + if (allWorkersComplete) { cairo_surface_mark_dirty(surface); g_main_context_invoke(NULL, queue_redraw_plane, NULL); } @@ -259,7 +259,7 @@ int main(int argc, char **argv) // integer, if the thread fails to start, it will simply be // overwritten by the same value in the next run of the loop pthread_t id; - if (pthread_create(&id, NULL, &writer_thread, &threads[count])) { + if (pthread_create(&id, NULL, &worker_thread, &threads[count])) { pthread_detach(id); fprintf(stderr, "Failed to create thread %d\n", i); continue; @@ -335,15 +335,15 @@ static void app_activate(GApplication *app) gboolean queue_redraw_plane(void *arg) { (void) arg; - bool allWritersHadCompleted = true; + bool allWorkersHadCompleted = true; for (int32_t i = 0; i < thread_count; i++) { if (!threads[i].complete) { - allWritersHadCompleted = false; + allWorkersHadCompleted = false; break; } } - if (!allWritersHadCompleted) { + if (!allWorkersHadCompleted) { return G_SOURCE_REMOVE; } @@ -357,14 +357,14 @@ void blit_plane(GtkDrawingArea *da, cairo_t *cr, int width, int height, gpointer (void) width; (void) height; (void) data; - bool allWritersHadCompleted = true; + bool allWorkersHadCompleted = true; for (int32_t i = 0; i < thread_count; i++) { if (!threads[i].complete) { - allWritersHadCompleted = false; + allWorkersHadCompleted = false; break; } } - if (allWritersHadCompleted) { + if (allWorkersHadCompleted) { cairo_set_source_surface(cr, surface, 0, 0); cairo_paint(cr); } @@ -382,27 +382,27 @@ void create_surface(GtkWidget *widget) pixmapAvailable = false; // Mark drawing area as unavailable pthread_mutex_unlock(&pixmapMutex); - bool allWritersStopped; + bool allWorkersStopped; do { // Wait until all writing threads have been stopped - allWritersStopped = true; + allWorkersStopped = true; for (int32_t i = 0; i < thread_count; i++) { if (threads[i].drawing) { - allWritersStopped = false; + allWorkersStopped = false; break; } } - } while (!allWritersStopped); + } while (!allWorkersStopped); // If all drawers hadn't completed, we need to call // cairo_surface_mark_dirty in the main thread - bool allWritersHadCompleted = true; + bool allWorkersHadCompleted = true; for (int32_t i = 0; i < thread_count; i++) { if (!threads[i].complete) { - allWritersHadCompleted = false; + allWorkersHadCompleted = false; break; } } - if (!allWritersHadCompleted && surface != NULL) { + if (!allWorkersHadCompleted && surface != NULL) { cairo_surface_mark_dirty(surface); }