]> git.ipfire.org Git - thirdparty/systemd.git/blame - job.c
initial commit
[thirdparty/systemd.git] / job.c
CommitLineData
60918275
LP
1/*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3#include <assert.h>
4
5#include "macro.h"
6#include "job.h"
7
8Job* job_new(Manager *m, JobType type, Name *name) {
9 Job *j;
10
11 assert(m);
12 assert(type < _JOB_TYPE_MAX);
13 assert(name);
14
15 if (!(j = new0(Job, 1)))
16 return NULL;
17
18 j->manager = m;
19 j->id = m->current_job_id++;
20 j->type = type;
21 j->name = name;
22
23 /* We don't link it here, that's what job_link() is for */
24
25 return j;
26}
27
28int job_link(Job *j) {
29 int r;
30
31 assert(j);
32 assert(!j->linked);
33
34 if ((r = hashmap_put(j->manager->jobs, UINT32_TO_PTR(j->id), j)) < 0)
35 return r;
36
37 j->name->meta.job = j;
38
39 j->linked = true;
40
41 return 0;
42}
43
44void job_free(Job *j) {
45 assert(j);
46
47 /* Detach from next 'bigger' objects */
48
49 if (j->linked) {
50 if (j->name && j->name->meta.job == j)
51 j->name->meta.job = NULL;
52
53 hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id));
54 }
55
56 /* Free data and next 'smaller' objects */
57
58 free(j);
59}