Changeset ff20afc in mainline for uspace/srv/sysman/repo.c


Ignore:
Timestamp:
2019-08-17T13:12:47Z (6 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.