Changeset ff20afc in mainline


Ignore:
Timestamp:
2019-08-17T13:12:47Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
5a88d87
Parents:
d5cca04
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-12-04 13:56:42)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-17 13:12:47)
Message:

sysman: Synchronize access to unit repository from other fibrils

Location:
uspace/srv/sysman
Files:
4 edited

Legend:

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

    rd5cca04 rff20afc  
    7676        }
    7777
    78         // TODO this is connection fibril, UNSYNCHRONIZED access to units!
    7978        unit_t *unit = repo_find_unit_by_name(unit_name);
    8079        if (unit == NULL) {
     
    107106        sysman_log(LVL_DEBUG2, "%s(%s, %x)", __func__, unit_name, flags);
    108107
    109         // TODO this is connection fibril, UNSYNCHRONIZED access to units!
    110108        unit_t *unit = repo_find_unit_by_name(unit_name);
    111109        if (unit == NULL) {
     
    148146        sysman_log(LVL_DEBUG2, "%s(%i, %x)", __func__, handle, flags);
    149147
    150         // TODO this is connection fibril, UNSYNCHRONIZED access to units!
    151148        unit_t *unit = repo_find_unit_by_handle(handle);
    152149        if (unit == NULL) {
     
    188185        size_t to_fill = size / sizeof(unit_handle_t);
    189186        size_t total = 0;
     187        repo_rlock();
    190188        list_foreach(units, units, unit_t, u) {
    191189                if (filled < to_fill) {
     
    194192                ++total;
    195193        }
     194        repo_runlock();
    196195        *act_size = total * sizeof(unit_handle_t);
    197196        return EOK;
     
    220219       
    221220       
    222         // TODO UNSYNCHRONIZED access to units!
    223221        rc = fill_handles_buffer(handles, size, &act_size);
    224222        if (rc != EOK) {
     
    246244        }
    247245       
    248         // TODO UNSYNCHRONIZED access to units!
    249246        unit_t *u = repo_find_unit_by_handle(IPC_GET_ARG1(*icall));
    250247        if (u == NULL) {
     
    262259static void sysman_unit_get_state(ipc_callid_t iid, ipc_call_t *icall)
    263260{
    264         // TODO UNSYNCHRONIZED access to units!
    265261        unit_t *u = repo_find_unit_by_handle(IPC_GET_ARG1(*icall));
    266262        if (u == NULL) {
  • uspace/srv/sysman/repo.c

    rd5cca04 rff20afc  
    4242static hash_table_t units_by_name;
    4343static hash_table_t units_by_handle;
     44/** Lock to protect units_by_name and units_by_handle, so that
     45 * repo_find_unit_by_* can be called also from non-event loop fibrils.
     46 */
     47static FIBRIL_RWLOCK_INITIALIZE(repo_lock);
    4448
    4549/* Hash table functions */
     
    137141        sysman_log(LVL_DEBUG2, "%s('%s')", __func__, unit_name(unit));
    138142
     143        fibril_rwlock_write_lock(&repo_lock);
    139144        if (hash_table_insert_unique(&units_by_name, &unit->units_by_name)) {
    140145                /* Pointers are same size as unit_handle_t both on 32b and 64b */
     
    143148                hash_table_insert(&units_by_handle, &unit->units_by_handle);
    144149                list_append(&unit->units, &units);
     150                fibril_rwlock_write_unlock(&repo_lock);
    145151                return EOK;
    146152        } else {
     153                fibril_rwlock_write_unlock(&repo_lock);
    147154                return EEXISTS;
    148155        }
     
    268275unit_t *repo_find_unit_by_name(const char *name)
    269276{
     277        fibril_rwlock_read_lock(&repo_lock);
    270278        ht_link_t *ht_link = hash_table_find(&units_by_name, (void *)name);
     279        fibril_rwlock_read_unlock(&repo_lock);
     280
    271281        if (ht_link != NULL) {
    272282                return hash_table_get_inst(ht_link, unit_t, units_by_name);
     
    278288unit_t *repo_find_unit_by_handle(unit_handle_t handle)
    279289{
     290        fibril_rwlock_read_lock(&repo_lock);
    280291        ht_link_t *ht_link = hash_table_find(&units_by_handle, &handle);
     292        fibril_rwlock_read_unlock(&repo_lock);
     293
    281294        if (ht_link != NULL) {
    282295                return hash_table_get_inst(ht_link, unit_t, units_by_handle);
     
    286299}
    287300
     301void repo_rlock(void)
     302{
     303        fibril_rwlock_read_lock(&repo_lock);
     304}
     305
     306void repo_runlock(void)
     307{
     308        fibril_rwlock_read_unlock(&repo_lock);
     309}
  • uspace/srv/sysman/repo.h

    rd5cca04 rff20afc  
    3838#define ANONYMOUS_SERVICE_MASK "service_%" PRIu64
    3939
     40/*
     41 * If you access units out of the main event-loop fibril call repo_rlock(),
     42 * repo_runlock().
     43 */
    4044extern list_t units;
    4145
     
    5660extern unit_t *repo_find_unit_by_handle(unit_handle_t);
    5761
     62extern void repo_rlock(void);
     63extern void repo_runlock(void);
    5864
    5965#endif
  • uspace/srv/sysman/sysman.c

    rd5cca04 rff20afc  
    359359/*
    360360 * Event handlers
    361  */
    362 
    363 // NOTE must run in main event loop fibril
     361 *
     362 * NOTE must run in main event loop fibril
     363 */
     364
    364365void sysman_event_job_process(void *data)
    365366{
Note: See TracChangeset for help on using the changeset viewer.