job make_job_with_id(unsigned int pri, unsigned int delay, unsigned int ttr, int body_size, tube tube, unsigned long long id) { job j; j = allocate_job(body_size); if (!j) return twarnx("OOM"), (job) 0; if (id) { j->id = id; if (id >= next_id) next_id = id + 1; } else { j->id = next_id++; } j->pri = pri; j->delay = delay; j->ttr = ttr; store_job(j); TUBE_ASSIGN(j->tube, tube); return j; }
void job_free(job j) { if (j) { TUBE_ASSIGN(j->tube, NULL); if (j->id) job_hash_free(j); } free(j); }
void job_free(job j) { if (j) { TUBE_ASSIGN(j->tube, NULL); if (j->state != JOB_STATE_COPY) job_hash_free(j); } free(j); }
job job_copy(job j) { job n; if (!j) return NULL; n = malloc(sizeof(struct job) + j->body_size); if (!n) return twarnx("OOM"), (job) 0; memcpy(n, j, sizeof(struct job) + j->body_size); n->next = n->prev = n; /* not in a linked list */ n->binlog = NULL; /* copies do not have refcnt on the binlog */ n->tube = 0; /* Don't use memcpy for the tube, which we must refcount. */ TUBE_ASSIGN(n->tube, j->tube); return n; }
job job_copy(job j) { job n; if (!j) return NULL; n = malloc(sizeof(struct job) + j->body_size); if (!n) return twarnx("OOM"), (job) 0; memcpy(n, j, sizeof(struct job) + j->body_size); n->next = n->prev = n; /* not in a linked list */ n->binlog = NULL; /* copies do not have refcnt on the binlog */ n->tube = 0; /* Don't use memcpy for the tube, which we must refcount. */ TUBE_ASSIGN(n->tube, j->tube); /* Mark this job as a copy so it can be appropriately freed later on */ n->state = JOB_STATE_COPY; return n; }