diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -177,7 +177,7 @@ int mortition(struct general_info *genin char *path_and_number; struct stat buffer; - isJobDone = 1; // set isJobDone to true + isJobDone = 1; for(counter = 0; counter < job->total_frames; counter++) { _distren_asprintf(&path_and_number, "%s/stor/job%d/out/%d.%s", @@ -187,18 +187,22 @@ int mortition(struct general_info *genin job->output_format); if(stat(path_and_number, &buffer) == -1) { + /** + missing frame found + */ job->frameset[counter].status = FRAMESETSTATUS_UNASSIGNED; job->completed_frames--; geninfo->total_frames_rendered--; - /** if a missing frame is found, set isJobDone to false */ isJobDone = 0; } free(path_and_number); } - /** if all frames were accounted for */ if(isJobDone) { + /** + all frames were accounted for + */ distrenjob_remove(geninfo, job); distrenjob_free(&job); geninfo->jobs_in_queue --; @@ -215,9 +219,11 @@ int mortition(struct general_info *genin return 0; } -/** scans the frames of a job to initialize a job after server */ -/* returns 1 if the job is completely done and there are no missing frames */ -/* returns 0 if a missing frame is found */ +/** + scans the frames of a job to initialize a job after server + @return 0 if the job is completely done and there are no missing frames, + 1 if missing frames are found. +*/ int restoreJobState(struct distrenjob *job) { short int isJobDone; @@ -239,10 +245,13 @@ int restoreJobState(struct distrenjob *j free(path_and_number); } - return isJobDone; + return !isJobDone; } -/** creates a structure from starting data, then calls another function to actually add that struct to the queue */ +/** + creates a structure from starting data, then calls another + function to actually add that struct to the queue. +*/ int prepare_distrenjob(struct general_info *geninfo, int type, char *name, char *submitter, char *email, int priority, int start_frame, int end_frame, int width, int height) { int counter2; @@ -266,7 +275,8 @@ int prepare_distrenjob(struct general_in distrenjob->priority = priority; distrenjob->width = width; distrenjob->height = height; - distrenjob->total_frames = (end_frame - start_frame + 1); /* sets the total number of frames in animation for status purposes */ + /** sets the total number of frames in animation for status purposes */ + distrenjob->total_frames = (end_frame - start_frame + 1); distrenjob->frameset = malloc(sizeof(struct frameset) * distrenjob->total_frames); if(!distrenjob->frameset) { @@ -274,7 +284,7 @@ int prepare_distrenjob(struct general_in return 1; } - /* prepares all the frames by setting that status to "unassigned" */ + /** prepares all the frames by setting that status to "unassigned" */ counter2 = start_frame; for(counter = 0; counter < distrenjob->total_frames; counter++){ distrenjob->frameset[counter].num = counter2; @@ -289,7 +299,9 @@ int prepare_distrenjob(struct general_in free(path_with_num); - /* add job to queue */ + /** + add job to queue + */ fprintf(stderr, "\nprepare_distrenjob: attempting distrenjob_serialize()\n"); distrenjob_serialize(distrenjob, serialfile); free(serialfile); @@ -309,7 +321,9 @@ int prepare_distrenjob(struct general_in } -/** distrenjob_enqueue: This function adds the job to the queue based on its priority */ +/** + distrenjob_enqueue: This function adds the job to the queue based on its priority +*/ int distrenjob_enqueue(struct general_info *geninfo, struct distrenjob *job) { struct distrenjob *prev_job; @@ -319,24 +333,34 @@ int distrenjob_enqueue(struct general_in head = &geninfo->head; prev_job = head; - // iterate through linked list of jobs - for(current_job = head->next; 1; current_job = current_job->next) + /** + iterate through linked jobs + */ + for(current_job = head->next; current_job; current_job = current_job->next) { - fprintf(stderr, "enqueue loop iteration\n"); - if(current_job == NULL){ // if it has reached the end of the list, add job there - prev_job->next = job; - fprintf(stderr, "adding job at end of queue\n"); - 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 highest priority given to jobs, head has a - job->next = current_job; // priority of zero so it will always be before other jobs - fprintf(stderr, "adding job before jobname: %s\n", current_job->name); - break; - } + fprintf(stderr, "enqueue loop iteration\n"); + if(job->priority < current_job->priority) + { + /** + if job's priority is less than current_job's priority, insert job + keep in mind 1 is the highest priority given to jobs, head has a + priority of zero so it will always be before other jobs + */ + prev_job->next = job; + job->next = current_job; + fprintf(stderr, "adding job before jobname: %s\n", current_job->name); + + return 0; + } prev_job = current_job; - } /* for(current_job) */ + } + + /** + if it has reached the end of the list, add job there + */ + prev_job->next = job; + fprintf(stderr, "adding job at end of queue\n"); return 0; }