Changeset - bbc92828afdd
[Not reviewed]
default
0 1 0
LordOfWar - 16 years ago 2009-09-12 18:45:51

created function \"change_job_priority\" and \"remove_job\" (this remove_job function recieves a job number and returns structure distrenjob, it was made to assist the change_job_priority function)

I also fixed an error where add_job_to_queue wasn't updating its prev_job pointer, which would of resulted in the loss of jobs between head and where the new job is inserted.
1 file changed with 28 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -277,99 +277,127 @@ void status_report_generator(struct dist
 
	  distrenjob_ptr->avg_render_time = (total_time / finished_frames); /*< extraneous parentheses! */
 
	  distrenjob_ptr->time_remaining = (distrenjob_ptr->avg_render_time * (distrenjob_ptr->total_frames - finished_frames)); /*< extraneous parentheses! */
 

	
 
	  if(finished_frames == distrenjob_ptr->total_frames)
 
	    /* If all frames are complete */
 
	    {
 
	      distrenjob_ptr->priority = 0; /*< set priority to zero to indicate job is complete */
 
	      distrenjob_remove(distrenjobs_head, distrenjob_ptr); /*< remove this job from the linkedlist */
 
	      general_info.total_finished_jobs++; /*< add one to the total finished jobs */
 

	
 
	    }
 
	  else if (finished_frames > distrenjob_ptr->total_frames)
 
	    /* just in case ;-) */
 
	    {
 
	      fprintf(stderr, "%s:%d: finished_frames (%lu) > distrenjob_ptr->total_frames (%d)",
 
		      __FILE__, __LINE__,
 
		      finished_frames,
 
		      distrenjob_ptr->total_frames);
 
	      abort();
 
	    }
 
	}
 

	
 
      general_info.rendering_clients = workers_working; /*< should this be a +=? */
 

	
 
      distrenjob_ptr = distrenjob_ptr->next; /*< This is the essence of linked lists and iterating through them */
 
      numjobs ++;
 
    } /* while(distrenjob_ptr) */
 

	
 
  general_info.jobs_in_queue = (highest_jobnum - general_info.total_finished_jobs); /*< extraneous parentheses! */
 
}
 

	
 

	
 
/** Structure Builder: This function creates frame array based on the total number of frames to be rendered, which will then be parsed by function frame_farmer. */
 
void add_job_to_queue(struct distrenjob *job) {
 
  struct distrenjob *prev_job = head; // create pointer to previous job
 
  struct distrenjob *current_job;     // create pointer to current_job (which job is being compared to)
 

	
 
  // iterate through linked list of jobs
 
  for(current_job = head; current_job != NULL; current_job = current_job->next){
 
    if(current_job == NULL){ // if it has reached the end of the list, add job there
 
      current_job = job;
 
      break;
 
    }
 
    else if(job->priority < current_job->priority){ // if job's priority is less than current_job's priority, insert job
 
      prev_job->next = job;                        // keep in mind 1 is the lowest priority
 
      job->next = current_job;
 
      break;
 
    }
 

	
 
    prev_job = current_job;
 
  } // end of for statement
 
}
 

	
 
void change_job_priority(int jobnum, int new_priority){
 
  struct distrenjob *job = &remove_job(jobnum);
 
  job->priority = new_priority;
 
  add_job_to_queue(job);
 
}
 

	
 
distrenjob remove_job(int jobnum_t){
 
  struct distrenjob *job;
 
  struct distrenjob *prev_job = head;
 

	
 
  for(job = head; job != NULL; job = job->next){
 
    if(job == NULL){
 
      return NULL;
 
    }
 
    if(job->jobnum = jobnum_t){
 
      prev_job = job->next;
 
      return job;
 
    }
 

	
 
    prev_job = job;
 
  }
 

	
 
  // job was not found if this point is reached
 
  return NULL;
 
}
 

	
 

	
 

	
 
/**
 
  Frame Finder: matches your computer up with a lovely frame to render
 
  TODO: Major issue here, the client needs to know the frame number, AND the job number!
 
  Notice that this function starts by looking at the oldest job first
 

	
 
	TODO: Link this up with the main() function to check if there are frames available or not and provide jobnum/framenum to the client
 

	
 
  @return 0 success, other: error
 
*/
 
int frame_finder(struct distrenjob *head, struct distrenjob **job, struct frameset **frame)
 
{
 
  int your_frame;  // your_frame is an integer value that will be given to the client as the frame number to render
 
  int your_job;	   // @TODO: Fixme: do we need this var? you_job is an integer value that must ALSO be given to the client
 

	
 
  unsigned short int found;
 
  unsigned short int priority;
 

	
 
  struct distrenjob *distrenjob_ptr;
 

	
 
  found = 0;
 
  while(!found)
 
    {
 
      /* enumerate through priority levels */
 
      for(priority = 10;
 
        priority > 0
 
            && !found;
 
           priority --)
 
	/* Find the job with the highest priority */
 
        for(distrenjob_ptr = head;
 
            distrenjob_ptr != NULL
 
            && !found;
 
            distrenjob_ptr = distrenjob_ptr->next)
 
          if(distrenjob_ptr->priority == priority)
 
	    found = 1;
 

	
 
      if(!found)
 
        {
 
          fprintf(stderr, "No more jobs to render\n");
 
          return 1;
 
        }
 

	
 
      found = 0;
 
      for(your_frame = 0;
 
        your_frame < distrenjob_ptr->total_frames;
 
        your_frame ++)
 
        if(distrenjob_ptr->frameset[your_frame].status == 0)
0 comments (0 inline, 0 general)