Changeset 6efec7e3 in mainline for uspace/srv/sysman/unit.c


Ignore:
Timestamp:
2019-08-03T07:38:34Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
59ba708
Parents:
4fe7fcb
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-03-17 19:54:13)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-03 07:38:34)
Message:

Unit polymorphism (simple mount), debug logging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/sysman/unit.c

    r4fe7fcb r6efec7e3  
    66#include <stdlib.h>
    77
     8#include "log.h"
    89#include "unit.h"
     10
     11/** Virtual method table for each unit type */
     12static unit_ops_t *unit_type_vmts[] = {
     13        [UNIT_TARGET]        = &unit_tgt_ops,
     14        [UNIT_MOUNT]         = &unit_mnt_ops,
     15        [UNIT_CONFIGURATION] = &unit_cfg_ops
     16};
    917
    1018static void unit_init(unit_t *unit, unit_type_t type)
     
    1220        assert(unit);
    1321
     22        memset(unit, 0, sizeof(unit_t));
    1423        link_initialize(&unit->units);
    1524       
     
    2130        list_initialize(&unit->dependants);
    2231        list_initialize(&unit->dependencies);
     32
     33        unit_type_vmts[unit->type]->init(unit);
    2334}
    2435
     
    3344
    3445/** Release resources used by unit structure */
    35 void unit_destroy(unit_t **unit)
     46void unit_destroy(unit_t **unit_ptr)
    3647{
    37         if (*unit == NULL)
     48        unit_t *unit = *unit_ptr;
     49        if (unit == NULL)
    3850                return;
     51
     52        unit_type_vmts[unit->type]->destroy(unit);
    3953        /* TODO:
    4054         *      edges,
    41          *      specific unit data,
    4255         *      check it's not an active unit,
    4356         *      other resources to come
    4457         */
    45         free(*unit);
    46         *unit = NULL;
     58        free(unit);
     59        unit_ptr = NULL;
     60}
     61
     62void unit_set_state(unit_t *unit, unit_state_t state)
     63{
     64        fibril_mutex_lock(&unit->state_mtx);
     65        unit->state = state;
     66        fibril_condvar_broadcast(&unit->state_cv);
     67        fibril_mutex_unlock(&unit->state_mtx);
    4768}
    4869
     
    5475int unit_start(unit_t *unit)
    5576{
    56         // TODO actually start the unit
    57         printf("Starting unit of type %i\n", unit->type);
    58         return EOK;
     77        sysman_log(LVL_DEBUG, "%s(%p)", __func__, unit);
     78        return unit_type_vmts[unit->type]->start(unit);
    5979}
Note: See TracChangeset for help on using the changeset viewer.