Changeset dda2602 in mainline for uspace/srv/sysman/configuration.c
- Timestamp:
- 2019-08-03T09:41:07Z (6 years ago)
- Children:
- dd5c623
- Parents:
- c0e4fc50
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-05-08 11:10:06)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-03 09:41:07)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/configuration.c
rc0e4fc50 rdda2602 38 38 #include "log.h" 39 39 40 static hash_table_t units; 40 LIST_INITIALIZE(units); 41 42 static hash_table_t units_by_name; 41 43 42 44 /* Hash table functions */ 43 static size_t units_ ht_hash(const ht_link_t *item)45 static size_t units_by_name_ht_hash(const ht_link_t *item) 44 46 { 45 47 unit_t *unit = 46 hash_table_get_inst(item, unit_t, units );48 hash_table_get_inst(item, unit_t, units_by_name); 47 49 return hash_string(unit->name); 48 50 } 49 51 50 static size_t units_ ht_key_hash(void *key)52 static size_t units_by_name_ht_key_hash(void *key) 51 53 { 52 54 return hash_string((const char *)key); 53 55 } 54 56 55 static bool units_ ht_equal(const ht_link_t *item1, const ht_link_t *item2)57 static bool units_by_name_ht_equal(const ht_link_t *item1, const ht_link_t *item2) 56 58 { 57 59 return str_cmp( 58 hash_table_get_inst(item1, unit_t, units )->name,59 hash_table_get_inst(item2, unit_t, units )->name) == 0;60 } 61 62 static bool units_ ht_key_equal(void *key, const ht_link_t *item)60 hash_table_get_inst(item1, unit_t, units_by_name)->name, 61 hash_table_get_inst(item2, unit_t, units_by_name)->name) == 0; 62 } 63 64 static bool units_by_name_ht_key_equal(void *key, const ht_link_t *item) 63 65 { 64 66 return str_cmp((const char *)key, 65 hash_table_get_inst(item, unit_t, units )->name) == 0;66 } 67 68 69 static hash_table_ops_t units_ ht_ops = {70 .hash = &units_ ht_hash,71 .key_hash = &units_ ht_key_hash,72 .equal = &units_ ht_equal,73 .key_equal = &units_ ht_key_equal,67 hash_table_get_inst(item, unit_t, units_by_name)->name) == 0; 68 } 69 70 71 static hash_table_ops_t units_by_name_ht_ops = { 72 .hash = &units_by_name_ht_hash, 73 .key_hash = &units_by_name_ht_key_hash, 74 .equal = &units_by_name_ht_equal, 75 .key_equal = &units_by_name_ht_key_equal, 74 76 .remove_callback = NULL // TODO realy unneeded? 75 77 }; … … 79 81 void configuration_init(void) 80 82 { 81 hash_table_create(&units , 0, 0, &units_ht_ops);83 hash_table_create(&units_by_name, 0, 0, &units_by_name_ht_ops); 82 84 } 83 85 … … 89 91 sysman_log(LVL_DEBUG2, "%s('%s')", __func__, unit_name(unit)); 90 92 91 if (hash_table_insert_unique(&units, &unit->units)) { 93 if (hash_table_insert_unique(&units_by_name, &unit->units_by_name)) { 94 list_append(&unit->units, &units); 92 95 return EOK; 93 96 } else { … … 102 105 static bool configuration_commit_unit(ht_link_t *ht_link, void *arg) 103 106 { 104 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units );107 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name); 105 108 // TODO state locking? 106 109 if (unit->state == STATE_EMBRYO) { … … 116 119 } 117 120 118 /** Marks newly added units as usable (via state change) */121 /** Marks newly added units_by_name as usable (via state change) */ 119 122 void configuration_commit(void) 120 123 { … … 122 125 123 126 /* 124 * Apply commit to all units , each commited unit commits its outgoing127 * Apply commit to all units_by_name, each commited unit commits its outgoing 125 128 * deps, thus eventually commiting all embryo deps as well. 126 129 */ 127 hash_table_apply(&units , &configuration_commit_unit, NULL);130 hash_table_apply(&units_by_name, &configuration_commit_unit, NULL); 128 131 } 129 132 130 133 static bool configuration_rollback_unit(ht_link_t *ht_link, void *arg) 131 134 { 132 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units );135 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name); 133 136 134 137 list_foreach_safe(unit->dependencies, cur_link, next_link) { … … 141 144 142 145 if (unit->state == STATE_EMBRYO) { 143 hash_table_remove_item(&units, ht_link); 146 hash_table_remove_item(&units_by_name, ht_link); 147 list_remove(&unit->units); 144 148 unit_destroy(&unit); 145 149 } … … 148 152 } 149 153 150 /** Remove all uncommited units and edges from configuratio154 /** Remove all uncommited units_by_name and edges from configuratio 151 155 * 152 156 * Memory used by removed object is released. … … 156 160 sysman_log(LVL_DEBUG2, "%s", __func__); 157 161 158 hash_table_apply(&units , &configuration_rollback_unit, NULL);162 hash_table_apply(&units_by_name, &configuration_rollback_unit, NULL); 159 163 } 160 164 … … 162 166 { 163 167 bool *has_error_ptr = arg; 164 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units );168 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name); 165 169 166 170 list_foreach(unit->dependencies, dependencies, unit_dependency_t, dep) { … … 187 191 } 188 192 189 /** Resolve unresolved dependencies between any pair of units 193 /** Resolve unresolved dependencies between any pair of units_by_name 190 194 * 191 195 * @return EOK on success … … 197 201 198 202 bool has_error = false; 199 hash_table_apply(&units , &configuration_resolve_unit, &has_error);203 hash_table_apply(&units_by_name, &configuration_resolve_unit, &has_error); 200 204 201 205 return has_error ? ENOENT : EOK; … … 204 208 unit_t *configuration_find_unit_by_name(const char *name) 205 209 { 206 ht_link_t *ht_link = hash_table_find(&units , (void *)name);210 ht_link_t *ht_link = hash_table_find(&units_by_name, (void *)name); 207 211 if (ht_link != NULL) { 208 return hash_table_get_inst(ht_link, unit_t, units );212 return hash_table_get_inst(ht_link, unit_t, units_by_name); 209 213 } else { 210 214 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.