Last change
on this file since c0c388d2 was c0c388d2, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago |
Sysman jobs memory management (refcnt)
|
-
Property mode
set to
100644
|
File size:
1.1 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 |
|
---|
[694253c] | 8 | static int sysman_create_closure_jobs(unit_t *unit, job_t **entry_job_ptr,
|
---|
| 9 | list_t *accumulator, job_type_t type)
|
---|
[f42ee6f] | 10 | {
|
---|
[694253c] | 11 | int rc = EOK;
|
---|
| 12 | job_t *job = job_create(type);
|
---|
| 13 | if (job == NULL) {
|
---|
| 14 | rc = ENOMEM;
|
---|
| 15 | goto fail;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | job->unit = unit;
|
---|
| 19 | // TODO set blocking jobs
|
---|
| 20 |
|
---|
| 21 | list_foreach(unit->dependencies, dependencies, unit_dependency_t, edge) {
|
---|
| 22 | rc = sysman_create_closure_jobs(edge->dependency, NULL,
|
---|
| 23 | accumulator, type);
|
---|
| 24 | if (rc != EOK) {
|
---|
| 25 | goto fail;
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
[c0c388d2] | 29 | /* Job is passed to the accumulator, i.e. no add_ref. */
|
---|
[694253c] | 30 | list_append(&job->link, accumulator);
|
---|
| 31 |
|
---|
| 32 | if (entry_job_ptr != NULL) {
|
---|
| 33 | *entry_job_ptr = job;
|
---|
| 34 | }
|
---|
[f42ee6f] | 35 | return EOK;
|
---|
[694253c] | 36 |
|
---|
| 37 | fail:
|
---|
[c0c388d2] | 38 | job_del_ref(&job);
|
---|
[694253c] | 39 | return rc;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | int sysman_unit_start(unit_t *unit)
|
---|
| 43 | {
|
---|
| 44 | list_t new_jobs;
|
---|
| 45 | list_initialize(&new_jobs);
|
---|
| 46 |
|
---|
| 47 | job_t *job = NULL;
|
---|
| 48 | int rc = sysman_create_closure_jobs(unit, &job, &new_jobs, JOB_START);
|
---|
| 49 | if (rc != EOK) {
|
---|
| 50 | return rc;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[c0c388d2] | 53 | // TODO handle errors when adding job accumulator
|
---|
[694253c] | 54 | job_queue_jobs(&new_jobs);
|
---|
| 55 |
|
---|
| 56 | return job_wait(job);
|
---|
[f42ee6f] | 57 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.