use global mbrot pointer

master
orange 12 years ago
parent 896478de2d
commit bc13bda65b

@ -38,6 +38,7 @@ void compmandelbrot_line(bitmap_t * mbrot, size_t y) {
bool diverges = false; bool diverges = false;
float complex z = 0; float complex z = 0;
int it; int it;
for (it = 1; it <= max_it; it++) { for (it = 1; it <= max_it; it++) {
/* z = z² + c */ /* z = z² + c */
@ -62,6 +63,9 @@ void compmandelbrot_line(bitmap_t * mbrot, size_t y) {
} }
} }
/* Mandelbrot bitmap. */
bitmap_t *mbrot;
/* Next line to compute. */ /* Next line to compute. */
size_t next_y = 0; size_t next_y = 0;
@ -70,8 +74,6 @@ pthread_mutex_t next_y_mutex;
/* Thread to compute mandelbrot. */ /* Thread to compute mandelbrot. */
void *compmandelbrot(void *arg) { void *compmandelbrot(void *arg) {
bitmap_t *mbrot = (bitmap_t *) arg;
size_t y = 0; size_t y = 0;
while (y < mbrot->height) { while (y < mbrot->height) {
int ret; int ret;
@ -191,11 +193,11 @@ int main(int argc, char *argv[]) {
} }
/* Set up mandelbrot bitmap. */ /* Set up mandelbrot bitmap. */
bitmap_t mbrot; mbrot = calloc(sizeof(bitmap_t), 1);
mbrot.width = 1600; mbrot->width = 1600;
mbrot.height = 1200; mbrot->height = 1200;
mbrot.pixels = calloc(sizeof(pixel_t), mbrot.width * mbrot.height); mbrot->pixels = calloc(sizeof(pixel_t), mbrot->width * mbrot->height);
assert(mbrot.pixels != NULL); assert(mbrot->pixels != NULL);
/* Start computing threads. */ /* Start computing threads. */
int ret; int ret;
@ -207,7 +209,7 @@ int main(int argc, char *argv[]) {
for (int t = 0; t < num_threads; t++) { for (int t = 0; t < num_threads; t++) {
ret = ret =
pthread_create(&threads[t], NULL, compmandelbrot, (void *) &mbrot); pthread_create(&threads[t], NULL, compmandelbrot, (void *) NULL);
assert(ret == 0); assert(ret == 0);
} }
@ -219,13 +221,14 @@ int main(int argc, char *argv[]) {
/* Save PNG */ /* Save PNG */
char *file = "multibrot.png"; char *file = "multibrot.png";
ret = save_png_to_file(&mbrot, file); ret = save_png_to_file(mbrot, file);
assert(ret == 0); assert(ret == 0);
/* Quit. */ /* Quit. */
pthread_exit(NULL); pthread_exit(NULL);
free(threads); free(threads);
free(mbrot.pixels); free(mbrot->pixels);
free(mbrot);
ret = pthread_mutex_destroy(&next_y_mutex); ret = pthread_mutex_destroy(&next_y_mutex);
assert(ret == 0); assert(ret == 0);
return 0; return 0;

Loading…
Cancel
Save