src/raytracer.cc
branchpyrit
changeset 5 2d97ea5e711a
parent 4 c73bc405ee7a
child 6 d8d596d26f25
equal deleted inserted replaced
4:c73bc405ee7a 5:2d97ea5e711a
   231 #ifdef PTHREADS
   231 #ifdef PTHREADS
   232 	int num_threads = 20;
   232 	int num_threads = 20;
   233 	printf("* pthreads enabled, using %d threads\n", num_threads);
   233 	printf("* pthreads enabled, using %d threads\n", num_threads);
   234 	pthread_t threads[num_threads];
   234 	pthread_t threads[num_threads];
   235 	for (int t = 0; t < num_threads; t++)
   235 	for (int t = 0; t < num_threads; t++)
   236 		threads[t] = NULL;
   236 		threads[t] = 0;
   237 	int t = 0;
   237 	int t = 0;
   238 #endif
   238 #endif
   239 
   239 
   240 	printf("* rendering row   0 (  0% done)");
   240 	printf("* rendering row   0 (  0%% done)");
   241 	for (int y = 0; y < h; y++) {
   241 	for (int y = 0; y < h; y++) {
   242 		d = (RenderrowData*) malloc(sizeof(RenderrowData));
   242 		d = (RenderrowData*) malloc(sizeof(RenderrowData));
   243 		d->rt = this;
   243 		d->rt = this;
   244 		d->w = w;
   244 		d->w = w;
   245 		d->vx = startx;
   245 		d->vx = startx;
   258 		/* when 't' owerflows, reset it */
   258 		/* when 't' owerflows, reset it */
   259 		if (t >= num_threads)
   259 		if (t >= num_threads)
   260 			t = 0;
   260 			t = 0;
   261 		/* wait for next thread in fifo queue, so the descriptor can be reused;
   261 		/* wait for next thread in fifo queue, so the descriptor can be reused;
   262 		   this also limits number of running threads */
   262 		   this also limits number of running threads */
   263 		if (threads[t] != NULL)
   263 		if (threads[t] != 0)
   264 			if (pthread_join(threads[t], (void**)&d) == 0)
   264 			if (pthread_join(threads[t], (void**)&d) == 0)
   265 				free(d);
   265 				free(d);
   266 #else
   266 #else
   267 		renderrow((void *)d);
   267 		renderrow((void *)d);
   268 		free(d);
   268 		free(d);