Пример #1
0
/* Shutdown:
 */
void lp_rast_destroy( struct lp_rasterizer *rast )
{
    unsigned i;

    /* Set exit_flag and signal each thread's work_ready semaphore.
     * Each thread will be woken up, notice that the exit_flag is set and
     * break out of its main loop.  The thread will then exit.
     */
    rast->exit_flag = TRUE;
    for (i = 0; i < rast->num_threads; i++) {
        pipe_semaphore_signal(&rast->tasks[i].work_ready);
    }

    /* Wait for threads to terminate before cleaning up per-thread data */
    for (i = 0; i < rast->num_threads; i++) {
        pipe_thread_wait(rast->threads[i]);
    }

    /* Clean up per-thread data */
    for (i = 0; i < rast->num_threads; i++) {
        pipe_semaphore_destroy(&rast->tasks[i].work_ready);
        pipe_semaphore_destroy(&rast->tasks[i].work_done);
    }

    /* for synchronizing rasterization threads */
    pipe_barrier_destroy( &rast->barrier );

    lp_scene_queue_destroy(rast->full_scenes);

    FREE(rast);
}
Пример #2
0
/* Shutdown:
 */
void lp_rast_destroy( struct lp_rasterizer *rast )
{
   unsigned i;

   /* Set exit_flag and signal each thread's work_ready semaphore.
    * Each thread will be woken up, notice that the exit_flag is set and
    * break out of its main loop.  The thread will then exit.
    */
   rast->exit_flag = TRUE;
   for (i = 0; i < rast->num_threads; i++) {
      pipe_semaphore_signal(&rast->tasks[i].work_ready);
   }

   /* Wait for threads to terminate before cleaning up per-thread data.
    * We don't actually call pipe_thread_wait to avoid dead lock on Windows
    * per https://bugs.freedesktop.org/show_bug.cgi?id=76252 */
   for (i = 0; i < rast->num_threads; i++) {
#ifdef _WIN32
      pipe_semaphore_wait(&rast->tasks[i].work_done);
#else
      thrd_join(rast->threads[i], NULL);
#endif
   }

   /* Clean up per-thread data */
   for (i = 0; i < rast->num_threads; i++) {
      pipe_semaphore_destroy(&rast->tasks[i].work_ready);
      pipe_semaphore_destroy(&rast->tasks[i].work_done);
   }
   for (i = 0; i < MAX2(1, rast->num_threads); i++) {
      align_free(rast->tasks[i].thread_data.cache);
   }

   /* for synchronizing rasterization threads */
   if (rast->num_threads > 0) {
      pipe_barrier_destroy( &rast->barrier );
   }

   lp_scene_queue_destroy(rast->full_scenes);

   FREE(rast);
}
int main(int argc, char *argv[])
{
   int i;

   for (i = 1; i < argc; ++i) {
      const char *arg = argv[i];
      if (strcmp(arg, "-v") == 0) {
         ++verbosity;
      } else {
         fprintf(stderr, "error: unrecognized option `%s`\n", arg);
         exit(EXIT_FAILURE);
      }
   }

   // Disable buffering
   setbuf(stdout, NULL);

   LOG("pipe_barrier_test starting\n");

   pipe_barrier_init(&barrier, NUM_THREADS);

   for (i = 0; i < NUM_THREADS; i++) {
      thread_ids[i] = i;
      threads[i] = u_thread_create(thread_function, (void *) &thread_ids[i]);
   }

   for (i = 0; i < NUM_THREADS; i++ ) {
      thrd_join(threads[i], NULL);
   }

   CHECK(p_atomic_read(&proceeded) == NUM_THREADS);

   pipe_barrier_destroy(&barrier);

   LOG("pipe_barrier_test exiting\n");

   return 0;
}
int main()
{
   int i;

   printf("pipe_barrier_test starting\n");

   pipe_barrier_init(&barrier, NUM_THREADS);

   for (i = 0; i < NUM_THREADS; i++) {
      thread_ids[i] = i;
      threads[i] = pipe_thread_create(thread_function, (void *) &thread_ids[i]);
   }

   for (i = 0; i < NUM_THREADS; i++ ) {
      pipe_thread_wait(threads[i]);
   }

   pipe_barrier_destroy(&barrier);

   printf("pipe_barrier_test exiting\n");

   return 0;
}