Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify: don't need a special case here.

I've been meaning to do this for a while. Now seemed like a good time.
This way is less code and more DRY.
  • Loading branch information...
commit bcd60630501fa7dcc788c60414a7e50c1069c7ef 1 parent 90d3ab8
@kr authored
Showing with 35 additions and 18 deletions.
  1. +7 −18 job.c
  2. +28 −0 tests/test_job.c
View
25 job.c
@@ -151,25 +151,14 @@ make_job_with_id(unsigned int pri, unsigned int delay, unsigned int ttr,
static void
job_hash_free(job j)
{
- int index = _get_job_hash_index(j->id);
- job jh = all_jobs ? all_jobs[index] : NULL;
-
- if (jh) {
- if (jh == j) {
- /* Special case the first */
- all_jobs[index] = jh->ht_next;
- all_jobs_used--;
- } else {
- job tmp;
- while (jh->ht_next && jh->ht_next != j) jh = jh->ht_next;
- if (jh->ht_next) {
- all_jobs_used--;
- tmp = jh->ht_next;
- jh->ht_next = jh->ht_next->ht_next;
- }
- }
- }
+ job *slot;
+ slot = &all_jobs[_get_job_hash_index(j->id)];
+ while (*slot && *slot != j) slot = &(*slot)->ht_next;
+ if (*slot) {
+ *slot = (*slot)->ht_next;
+ --all_jobs_used;
+ }
}
void
View
28 tests/test_job.c
@@ -66,6 +66,34 @@ __CUT__job_test_large_pris()
}
void
+__CUT__job_test_hash_free()
+{
+ job j;
+ unsigned long long int jid = 83;
+
+ j = make_job_with_id(0, 0, 1, 0, default_tube, jid);
+ job_free(j);
+
+ ASSERT(!job_find(jid), "job should be missing");
+}
+
+void
+__CUT__job_test_hash_free_next()
+{
+ job a, b;
+ unsigned long long int aid = 97, bid = 12386;
+
+ b = make_job_with_id(0, 0, 1, 0, default_tube, bid);
+ a = make_job_with_id(0, 0, 1, 0, default_tube, aid);
+
+ ASSERT(a->ht_next == b, "b should be chained to a");
+
+ job_free(b);
+
+ ASSERT(a->ht_next == NULL, "job should be missing");
+}
+
+void
__CUT_TAKEDOWN__job()
{
TUBE_ASSIGN(default_tube, 0);
Please sign in to comment.
Something went wrong with that request. Please try again.