/** * This is the thread's main entrypoint. * It's a simple loop: * 1. wait for work * 2. do work * 3. signal that we're done */ static PIPE_THREAD_ROUTINE( thread_function, init_data ) { struct lp_rasterizer_task *task = (struct lp_rasterizer_task *) init_data; struct lp_rasterizer *rast = task->rast; boolean debug = false; unsigned fpstate = util_fpstate_get(); /* Make sure that denorms are treated like zeros. This is * the behavior required by D3D10. OpenGL doesn't care. */ util_fpstate_set_denorms_to_zero(fpstate); while (1) { /* wait for work */ if (debug) debug_printf("thread %d waiting for work\n", task->thread_index); pipe_semaphore_wait(&task->work_ready); if (rast->exit_flag) break; if (task->thread_index == 0) { /* thread[0]: * - get next scene to rasterize * - map the framebuffer surfaces */ lp_rast_begin( rast, lp_scene_dequeue( rast->full_scenes, TRUE ) ); } /* Wait for all threads to get here so that threads[1+] don't * get a null rast->curr_scene pointer. */ pipe_barrier_wait( &rast->barrier ); /* do work */ if (debug) debug_printf("thread %d doing work\n", task->thread_index); rasterize_scene(task, rast->curr_scene); /* wait for all threads to finish with this scene */ pipe_barrier_wait( &rast->barrier ); /* XXX: shouldn't be necessary: */ if (task->thread_index == 0) { lp_rast_end( rast ); } /* signal done with work */ if (debug) debug_printf("thread %d done working\n", task->thread_index); pipe_semaphore_signal(&task->work_done); } return 0; }
/** * This is the thread's main entrypoint. * It's a simple loop: * 1. wait for work * 2. do work * 3. signal that we're done */ static PIPE_THREAD_ROUTINE( thread_func, init_data ) { struct lp_rasterizer_task *task = (struct lp_rasterizer_task *) init_data; struct lp_rasterizer *rast = task->rast; boolean debug = false; while (1) { /* wait for work */ if (debug) debug_printf("thread %d waiting for work\n", task->thread_index); pipe_semaphore_wait(&task->work_ready); if (rast->exit_flag) break; if (task->thread_index == 0) { /* thread[0]: * - get next scene to rasterize * - map the framebuffer surfaces */ lp_rast_begin( rast, lp_scene_dequeue( rast->full_scenes, TRUE ) ); } /* Wait for all threads to get here so that threads[1+] don't * get a null rast->curr_scene pointer. */ pipe_barrier_wait( &rast->barrier ); /* do work */ if (debug) debug_printf("thread %d doing work\n", task->thread_index); rasterize_scene(task, rast->curr_scene); /* wait for all threads to finish with this scene */ pipe_barrier_wait( &rast->barrier ); /* XXX: shouldn't be necessary: */ if (task->thread_index == 0) { lp_rast_end( rast ); } /* signal done with work */ if (debug) debug_printf("thread %d done working\n", task->thread_index); pipe_semaphore_signal(&task->work_done); } return NULL; }
static PIPE_THREAD_ROUTINE(thread_function, thread_data) { int thread_id = *((int *) thread_data); printf("thread %d starting\n", thread_id); os_time_sleep(thread_id * 1000 * 1000); printf("thread %d before barrier\n", thread_id); pipe_barrier_wait(&barrier); printf("thread %d exiting\n", thread_id); return NULL; }
static int thread_function(void *thread_data) { int thread_id = *((int *) thread_data); LOG("thread %d starting\n", thread_id); os_time_sleep(thread_id * 100 * 1000); LOG("thread %d before barrier\n", thread_id); CHECK(p_atomic_read(&proceeded) == 0); p_atomic_inc(&waiting); pipe_barrier_wait(&barrier); CHECK(p_atomic_read(&waiting) == NUM_THREADS); p_atomic_inc(&proceeded); LOG("thread %d exiting\n", thread_id); return 0; }