Last change
on this file since 6efec7e3 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
|
Rev | Line | |
---|
[694253c] | 1 | #include <adt/list.h>
|
---|
[f42ee6f] | 2 | #include <errno.h>
|
---|
| 3 |
|
---|
[694253c] | 4 | #include "dep.h"
|
---|
| 5 | #include "job.h"
|
---|
[f42ee6f] | 6 | #include "sysman.h"
|
---|
| 7 |
|
---|
[4fe7fcb] | 8 | /** Create jobs for cluser of given unit.
|
---|
| 9 | *
|
---|
| 10 | * @note Using recursion, limits "depth" of dependency graph.
|
---|
| 11 | */
|
---|
[694253c] | 12 | static int sysman_create_closure_jobs(unit_t *unit, job_t **entry_job_ptr,
|
---|
| 13 | list_t *accumulator, job_type_t type)
|
---|
[f42ee6f] | 14 | {
|
---|
[694253c] | 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) {
|
---|
[4fe7fcb] | 25 | job_t *blocking_job = NULL;
|
---|
| 26 | rc = sysman_create_closure_jobs(edge->dependency, &blocking_job,
|
---|
[694253c] | 27 | accumulator, type);
|
---|
| 28 | if (rc != EOK) {
|
---|
| 29 | goto fail;
|
---|
| 30 | }
|
---|
[4fe7fcb] | 31 |
|
---|
| 32 | rc = job_add_blocking_job(job, blocking_job);
|
---|
| 33 | if (rc != EOK) {
|
---|
| 34 | goto fail;
|
---|
| 35 | }
|
---|
[694253c] | 36 | }
|
---|
| 37 |
|
---|
[c0c388d2] | 38 | /* Job is passed to the accumulator, i.e. no add_ref. */
|
---|
[694253c] | 39 | list_append(&job->link, accumulator);
|
---|
| 40 |
|
---|
| 41 | if (entry_job_ptr != NULL) {
|
---|
| 42 | *entry_job_ptr = job;
|
---|
| 43 | }
|
---|
[f42ee6f] | 44 | return EOK;
|
---|
[694253c] | 45 |
|
---|
| 46 | fail:
|
---|
[c0c388d2] | 47 | job_del_ref(&job);
|
---|
[694253c] | 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 |
|
---|
[c0c388d2] | 62 | // TODO handle errors when adding job accumulator
|
---|
[694253c] | 63 | job_queue_jobs(&new_jobs);
|
---|
| 64 |
|
---|
| 65 | return job_wait(job);
|
---|
[f42ee6f] | 66 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.