Changeset 3f7e1f24 in mainline for uspace/srv/sysman/main.c


Ignore:
Timestamp:
2019-08-03T08:28:26Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
095d03c
Parents:
d7c5fc0
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-04-22 17:54:08)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-03 08:28:26)
Message:

sysman: Refactored job manipulation (event loop + one main fibril)

File:
1 edited

Legend:

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

    rd7c5fc0 r3f7e1f24  
    3737#include "dep.h"
    3838#include "job.h"
     39#include "log.h"
    3940#include "sysman.h"
    4041#include "unit.h"
     
    4748}
    4849
    49 static int sysman_entry_point(void *arg) {
    50         /*
    51          * Build hard coded configuration.
    52          *
    53          * Strings are allocated on heap, so that they can be free'd by an
    54          * owning unit.
    55          */
     50/** Build hard coded configuration */
     51static job_t *create_entry_configuration(void) {
    5652        int result = EOK;
    5753        unit_t *mnt_initrd = NULL;
     
    107103        configuration_commit();
    108104
    109         result = sysman_unit_start(tgt_default);
    110 
    111         return result;
     105        job_t *first_job = job_create(tgt_default, STATE_STARTED);
     106        if (first_job == NULL) {
     107                goto fail;
     108        }
     109        return first_job;
    112110
    113111fail:
     112        // TODO cannot destroy units after they're added to configuration
    114113        unit_destroy(&tgt_default);
    115114        unit_destroy(&cfg_init);
    116115        unit_destroy(&mnt_initrd);
    117         return result;
     116        return NULL;
     117}
     118
     119static void first_job_handler(void *object, void *unused)
     120{
     121        job_t *job = object;
     122        sysman_log(LVL_DEBUG, "First job retval: %i.", job->retval);
     123        job_del_ref(&job);
    118124}
    119125
     
    122128        printf(NAME ": HelenOS system daemon\n");
    123129
     130        /*
     131         * Initialize global structures
     132         */
    124133        configuration_init();
     134        sysman_events_init();
    125135        job_queue_init();
    126136
    127137        /*
    128          * Create and start initial configuration asynchronously
    129          * so that we can start server's fibril that may be used
    130          * when executing the start.
     138         * Create initial configuration while we are in a single fibril, keep
     139         * the job and run it when event loop is running.
    131140         */
    132         fid_t entry_fibril = fibril_create(sysman_entry_point, NULL);
    133         fibril_add_ready(entry_fibril);
     141        job_t *first_job = create_entry_configuration();
    134142
    135         /* Prepare and start sysman server */
     143        /*
     144         * Event loop runs in separate fibril, all consequent access to global
     145         * structure is made from this fibril only.
     146         */
     147        fid_t event_loop_fibril = fibril_create(sysman_events_loop, NULL);
     148        fibril_add_ready(event_loop_fibril);
     149
     150        /* Queue first job for processing */
     151        sysman_object_observer(first_job, &first_job_handler, NULL);
     152        sysman_raise_event(&sysman_event_job_process, first_job);
     153
     154        /* Start sysman server */
    136155        async_set_client_connection(sysman_connection);
    137156
     
    139158        async_manager();
    140159
     160        /* not reached */
    141161        return 0;
    142162}
Note: See TracChangeset for help on using the changeset viewer.