Last change
on this file since 694253c was 694253c, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago |
Skeleton for sysman (unit) jobs control
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[f42ee6f] | 1 | #include <assert.h>
|
---|
[694253c] | 2 | #include <errno.h>
|
---|
| 3 | #include <fibril_synch.h>
|
---|
[f42ee6f] | 4 | #include <mem.h>
|
---|
[694253c] | 5 | #include <stdio.h>
|
---|
[f42ee6f] | 6 | #include <stdlib.h>
|
---|
| 7 |
|
---|
| 8 | #include "unit.h"
|
---|
| 9 |
|
---|
| 10 | static void unit_init(unit_t *unit, unit_type_t type)
|
---|
| 11 | {
|
---|
| 12 | assert(unit);
|
---|
| 13 |
|
---|
| 14 | link_initialize(&unit->units);
|
---|
[694253c] | 15 |
|
---|
[f42ee6f] | 16 | unit->type = type;
|
---|
| 17 | unit->state = STATE_EMBRYO;
|
---|
[694253c] | 18 | fibril_mutex_initialize(&unit->state_mtx);
|
---|
| 19 | fibril_condvar_initialize(&unit->state_cv);
|
---|
| 20 |
|
---|
| 21 | list_initialize(&unit->dependants);
|
---|
| 22 | list_initialize(&unit->dependencies);
|
---|
[f42ee6f] | 23 | }
|
---|
| 24 |
|
---|
| 25 | unit_t *unit_create(unit_type_t type)
|
---|
| 26 | {
|
---|
| 27 | unit_t *unit = malloc(sizeof(unit_t));
|
---|
| 28 | if (unit != NULL) {
|
---|
| 29 | unit_init(unit, type);
|
---|
| 30 | }
|
---|
| 31 | return unit;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | /** Release resources used by unit structure */
|
---|
| 35 | void unit_destroy(unit_t **unit)
|
---|
| 36 | {
|
---|
| 37 | if (*unit == NULL)
|
---|
| 38 | return;
|
---|
| 39 | /* TODO:
|
---|
| 40 | * edges,
|
---|
| 41 | * specific unit data,
|
---|
| 42 | * check it's not an active unit,
|
---|
| 43 | * other resources to come
|
---|
| 44 | */
|
---|
| 45 | free(*unit);
|
---|
| 46 | *unit = NULL;
|
---|
| 47 | }
|
---|
[694253c] | 48 |
|
---|
| 49 | /** Issue request to restarter to start a unit
|
---|
| 50 | *
|
---|
| 51 | * Return from this function only means start request was issued.
|
---|
| 52 | * If you need to wait for real start of the unit, use waiting on state_cv.
|
---|
| 53 | */
|
---|
| 54 | int unit_start(unit_t *unit)
|
---|
| 55 | {
|
---|
| 56 | // TODO actually start the unit
|
---|
| 57 | printf("Starting unit of type %i\n", unit->type);
|
---|
| 58 | return EOK;
|
---|
| 59 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.