Exemplo n.º 1
0
static __exit void counter_exit(void)
{
	pr_info("Exiting concurrent counter module\n");

	jobs_finish();

	pr_info("actual(count=%u), expected(count=%u)\n",
			count, TIMES_INC * MAX_JOBS);
}
Exemplo n.º 2
0
/**
 * Thread function
 * @param sp State pointer
 */
void * thread_func( void * sp )
{
  struct job job;
  struct state * s;
  struct threads * t;
  int has_next, must_save;

  if ( !( s = (struct state*)sp ) || !( t = s->thread_mngr ) )
    pthread_exit( NULL );

  has_next = 0, must_save = 0;
  while ( t->running )
  {
    pthread_mutex_lock( &t->queue_lock );

    // must_save will be one if a chunk must be saved
    // if jobs_finish will receive 1 for must_save,
    // it will know that it can execute stuff which
    // needs to be after a chunk is saved
    if ( has_next )
    {
      jobs_finish( s, &job, &must_save );
    }

    // If the last processed chunk must be saved,
    // we lock on c->data_primes and save it
    if ( must_save )
    {
      pthread_mutex_unlock( &t->queue_lock );

      pthread_mutex_lock( &t->save_lock );
      jobs_save_finished( s, job.filtered_chunk);
      pthread_mutex_unlock( &t->save_lock );
    }

    // Otherwise, we process a new chunk
    else
    {
      has_next = jobs_next( s, &job );
      pthread_mutex_unlock( &t->queue_lock );

      if ( has_next )
        jobs_run( s, &job );
    }
  }

  pthread_exit( NULL );
}