void VariantJobServer::PushCurVariantOntoJobs(ofstream &outVCFFile,
    ofstream &filterVCFFile,
    vcf::VariantCallFile &vcfFile,
    InputStructures &global_context,
    ExtendParameters *parameters) {
  variant->isHotSpot = isHotSpot;  // see TODO above


  //@TODO: the logic here is slightly more complex than optimal
  if (variant_thread_job_spec == NULL) {
    variant_thread_job_spec = new variantThreadInfo(outVCFFile, filterVCFFile, parameters, &global_context, all_thread_master);
  }

  if (variant_thread_job_spec->ReadyForAnotherVariant()) {
    variant_thread_job_spec->PushVariantOntoJob(variant);
  }
  else {
    //check for the number of running threads and if less than MAX create new thread and pass the job
    all_thread_master.WaitForFreeThread();

    if (all_thread_master.max_threads_sem.count < all_thread_master.max_threads_available) {
      all_thread_master.StartJob(variant_thread_job_spec, false, global_context.DEBUG);

      variant_thread_job_spec = NULL;
      variant_thread_job_spec = new variantThreadInfo(outVCFFile, filterVCFFile, parameters, &global_context, all_thread_master);
      variant_thread_job_spec->PushVariantOntoJob(variant);

    }
    else {
      cerr << "FATAL: thought I had a thread available but I didn't" << endl;
      exit(-1);
    }
    //Added for 3.6.1 Patch to clear thread resource after they terminate. Need to move this to use thread pools instead.
    if (all_thread_master.thread_tracker.size() > (size_t) 3*all_thread_master.max_threads_available) {
      std::vector<pthread_t*>::iterator thread_itr = all_thread_master.thread_tracker.begin();
      int counter = 0;
      int rc = 0;
      while (counter < all_thread_master.max_threads_available && thread_itr != all_thread_master.thread_tracker.end()) {
        rc = pthread_join(**thread_itr, NULL);
        if (rc) {
          cerr << "FATAL: pthread_join returned non-zero return code " << rc << endl;
          exit(-1);
        }
        //remove the thread reference since it has completed successfully to release it's resources
        delete *thread_itr;
        thread_itr = all_thread_master.thread_tracker.erase(thread_itr);
        counter++;
      }
    }

  }

  NewVariant(vcfFile);
}
示例#2
0
void VariantJobServer::PushCurVariantOntoJobs(ofstream &outVCFFile,
        ofstream &filterVCFFile,
        vcf::VariantCallFile &vcfFile,
        InputStructures &global_context,
        ExtendParameters *parameters) {
    variant->isHotSpot = isHotSpot;  // see TODO above


    //@TODO: the logic here is slightly more complex than optimal
    // need a new job, create one
    if (variant_thread_job_spec == NULL) {
        variant_thread_job_spec = new variantThreadInfo(outVCFFile, filterVCFFile, parameters, &global_context, all_thread_master);
    }
   // if job can take another variant, go for it
    if (variant_thread_job_spec->ReadyForAnotherVariant()) {
        variant_thread_job_spec->PushVariantOntoJob(variant);
    }
    else {
      // ready to fire off the job
        //check for the number of running threads and if less than MAX create new thread and pass the job
        all_thread_master.WaitForFreeThread();

        if (all_thread_master.max_threads_sem.count < all_thread_master.max_threads_available) {
            all_thread_master.StartJob(variant_thread_job_spec, false, global_context.DEBUG);
// generate a new job to handle the variant we were passed
            variant_thread_job_spec = NULL;
            variant_thread_job_spec = new variantThreadInfo(outVCFFile, filterVCFFile, parameters, &global_context, all_thread_master);
            variant_thread_job_spec->PushVariantOntoJob(variant);

        }
        else {
            cerr << "FATAL: thought I had a thread available but I didn't" << endl;
            exit(-1);
        }
        //Added for 3.6.1 Patch to clear thread resource after they terminate. Need to move this to use thread pools instead.
        RefreshThreadPool();

    }
// get a new variant to handle the next case
    NewVariant(vcfFile);
}