Skip to content

Commit

Permalink
Get ride of the dreaded my_compare function.
Browse files Browse the repository at this point in the history
Give the function a somewhat better name so you at least get a clue as
to what its doing.
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 8756213 commit a5d3674
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/dird/ua_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,20 +852,23 @@ static void prt_runtime(UAContext *ua, sched_pkt *sp)
/*
* Sort items by runtime, priority
*/
static int my_compare(void *item1, void *item2)
static int compare_by_runtime_priority(void *item1, void *item2)
{
sched_pkt *p1 = (sched_pkt *)item1;
sched_pkt *p2 = (sched_pkt *)item2;

if (p1->runtime < p2->runtime) {
return -1;
} else if (p1->runtime > p2->runtime) {
return 1;
}

if (p1->priority < p2->priority) {
return -1;
} else if (p1->priority > p2->priority) {
return 1;
}

return 0;
}

Expand Down Expand Up @@ -926,7 +929,7 @@ static void list_scheduled_jobs(UAContext *ua)
get_job_storage(&store, job, run);
sp->store = store.store;
Dmsg3(250, "job=%s store=%s MediaType=%s\n", job->name(), sp->store->name(), sp->store->media_type);
sched.binary_insert_multiple(sp, my_compare);
sched.binary_insert_multiple(sp, compare_by_runtime_priority);
num_jobs++;
}
} /* end for loop over resources */
Expand Down
12 changes: 6 additions & 6 deletions src/stored/vol_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void debug_list_volumes(const char *imsg);
/*
* For append volumes the key is the VolumeName.
*/
static int my_compare(void *item1, void *item2)
static int compare_by_volumename(void *item1, void *item2)
{
return strcmp(((VOLRES *)item1)->vol_name, ((VOLRES *)item2)->vol_name);
}
Expand Down Expand Up @@ -401,7 +401,7 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName)
/*
* Now try to insert the new Volume
*/
vol = (VOLRES *)vol_list->binary_insert(nvol, my_compare);
vol = (VOLRES *)vol_list->binary_insert(nvol, compare_by_volumename);
if (vol != nvol) {
Dmsg2(dbglvl, "Found vol=%s dev-same=%d\n", vol->vol_name, dev==vol->dev);
/*
Expand Down Expand Up @@ -565,7 +565,7 @@ VOLRES *find_volume(const char *VolumeName)
/* Do not lock reservations here */
lock_volumes();
vol.vol_name = bstrdup(VolumeName);
fvol = (VOLRES *)vol_list->binary_search(&vol, my_compare);
fvol = (VOLRES *)vol_list->binary_search(&vol, compare_by_volumename);
free(vol.vol_name);
Dmsg2(dbglvl, "find_vol=%s found=%d\n", VolumeName, fvol!=NULL);
debug_list_volumes("find_volume");
Expand All @@ -590,8 +590,8 @@ static VOLRES *find_read_volume(const char *VolumeName)
/* Do not lock reservations here */
lock_read_volumes();
vol.vol_name = bstrdup(VolumeName);
/* Note, we do want a simple my_compare on volume name only here */
fvol = (VOLRES *)read_vol_list->binary_search(&vol, my_compare);
/* Note, we do want a simple compare_by_volumename on volume name only here */
fvol = (VOLRES *)read_vol_list->binary_search(&vol, compare_by_volumename);
free(vol.vol_name);
Dmsg2(dbglvl, "find_read_vol=%s found=%d\n", VolumeName, fvol!=NULL);
unlock_read_volumes();
Expand Down Expand Up @@ -820,7 +820,7 @@ dlist *dup_vol_list(JCR *jcr)
memset(tvol, 0, sizeof(VOLRES));
tvol->vol_name = bstrdup(vol->vol_name);
tvol->dev = vol->dev;
nvol = (VOLRES *)temp_vol_list->binary_insert(tvol, my_compare);
nvol = (VOLRES *)temp_vol_list->binary_insert(tvol, compare_by_volumename);
if (tvol != nvol) {
tvol->dev = NULL; /* don't zap dev entry */
free_vol_item(tvol);
Expand Down

0 comments on commit a5d3674

Please sign in to comment.