Last change
on this file since 4fe7fcb was 4fe7fcb, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago |
Transform unit dependencies to job ordering
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | #include <adt/list.h>
|
---|
2 | #include <errno.h>
|
---|
3 |
|
---|
4 | #include "dep.h"
|
---|
5 | #include "job.h"
|
---|
6 | #include "sysman.h"
|
---|
7 |
|
---|
8 | /** Create jobs for cluser of given unit.
|
---|
9 | *
|
---|
10 | * @note Using recursion, limits "depth" of dependency graph.
|
---|
11 | */
|
---|
12 | static int sysman_create_closure_jobs(unit_t *unit, job_t **entry_job_ptr,
|
---|
13 | list_t *accumulator, job_type_t type)
|
---|
14 | {
|
---|
15 | int rc = EOK;
|
---|
16 | job_t *job = job_create(type);
|
---|
17 | if (job == NULL) {
|
---|
18 | rc = ENOMEM;
|
---|
19 | goto fail;
|
---|
20 | }
|
---|
21 |
|
---|
22 | job->unit = unit;
|
---|
23 |
|
---|
24 | list_foreach(unit->dependencies, dependencies, unit_dependency_t, edge) {
|
---|
25 | job_t *blocking_job = NULL;
|
---|
26 | rc = sysman_create_closure_jobs(edge->dependency, &blocking_job,
|
---|
27 | accumulator, type);
|
---|
28 | if (rc != EOK) {
|
---|
29 | goto fail;
|
---|
30 | }
|
---|
31 |
|
---|
32 | rc = job_add_blocking_job(job, blocking_job);
|
---|
33 | if (rc != EOK) {
|
---|
34 | goto fail;
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | /* Job is passed to the accumulator, i.e. no add_ref. */
|
---|
39 | list_append(&job->link, accumulator);
|
---|
40 |
|
---|
41 | if (entry_job_ptr != NULL) {
|
---|
42 | *entry_job_ptr = job;
|
---|
43 | }
|
---|
44 | return EOK;
|
---|
45 |
|
---|
46 | fail:
|
---|
47 | job_del_ref(&job);
|
---|
48 | return rc;
|
---|
49 | }
|
---|
50 |
|
---|
51 | int sysman_unit_start(unit_t *unit)
|
---|
52 | {
|
---|
53 | list_t new_jobs;
|
---|
54 | list_initialize(&new_jobs);
|
---|
55 |
|
---|
56 | job_t *job = NULL;
|
---|
57 | int rc = sysman_create_closure_jobs(unit, &job, &new_jobs, JOB_START);
|
---|
58 | if (rc != EOK) {
|
---|
59 | return rc;
|
---|
60 | }
|
---|
61 |
|
---|
62 | // TODO handle errors when adding job accumulator
|
---|
63 | job_queue_jobs(&new_jobs);
|
---|
64 |
|
---|
65 | return job_wait(job);
|
---|
66 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.