Changeset 015b147 in mainline for uspace/srv/sysman/repo.c
- Timestamp:
- 2019-08-17T13:52:32Z (5 years ago)
- Children:
- be07995
- Parents:
- 31ef7c1
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2016-01-10 17:17:19)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-17 13:52:32)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/repo.c
r31ef7c1 r015b147 38 38 #include "log.h" 39 39 40 LIST_INITIALIZE(units );40 LIST_INITIALIZE(units_); 41 41 42 42 static hash_table_t units_by_name; … … 119 119 static void repo_remove_unit_internal(unit_t *u) 120 120 { 121 assert(fibril_rwlock_is_write_locked(&repo_lock)); 122 121 123 hash_table_remove_item(&units_by_name, &u->units_by_name); 122 124 hash_table_remove_item(&units_by_handle, &u->units_by_handle); … … 125 127 // TODO decrease refcount of unit 126 128 // unit may be referenced e.g. from running job, thus we cannot simply destroy it 129 } 130 131 static unit_t *repo_find_unit_by_name_internal(const char *name, bool lock) 132 { 133 sysman_log(LVL_DEBUG2, "%s(%s, %i)", __func__, name, lock); 134 if (lock) fibril_rwlock_read_lock(&repo_lock); 135 ht_link_t *ht_link = hash_table_find(&units_by_name, (void *)name); 136 if (lock) fibril_rwlock_read_unlock(&repo_lock); 137 138 if (ht_link != NULL) { 139 return hash_table_get_inst(ht_link, unit_t, units_by_name); 140 } else { 141 return NULL; 142 } 127 143 } 128 144 … … 139 155 assert(unit->handle == 0); 140 156 assert(unit->name != NULL); 157 assert(fibril_rwlock_is_write_locked(&repo_lock)); 141 158 sysman_log(LVL_DEBUG2, "%s('%s')", __func__, unit_name(unit)); 142 159 143 fibril_rwlock_write_lock(&repo_lock);144 160 if (hash_table_insert_unique(&units_by_name, &unit->units_by_name)) { 145 161 /* Pointers are same size as unit_handle_t both on 32b and 64b */ … … 147 163 148 164 hash_table_insert(&units_by_handle, &unit->units_by_handle); 149 list_append(&unit->units, &units); 150 fibril_rwlock_write_unlock(&repo_lock); 165 list_append(&unit->units, &units_); 151 166 return EOK; 152 167 } else { 153 fibril_rwlock_write_unlock(&repo_lock);154 168 return EEXISTS; 155 169 } … … 162 176 } 163 177 164 void repo_begin_update(void) { 165 sysman_log(LVL_DEBUG2, "%s", __func__); 178 void repo_begin_update_(void) { 179 sysman_log(LVL_DEBUG2, "%s", __func__); 180 fibril_rwlock_write_lock(&repo_lock); 166 181 } 167 182 … … 196 211 */ 197 212 hash_table_apply(&units_by_name, &repo_commit_unit, NULL); 213 fibril_rwlock_write_unlock(&repo_lock); 198 214 } 199 215 … … 228 244 229 245 hash_table_apply(&units_by_name, &repo_rollback_unit, NULL); 246 fibril_rwlock_write_unlock(&repo_lock); 230 247 } 231 248 … … 243 260 244 261 unit_t *output = 245 repo_find_unit_by_name (e->output_name);262 repo_find_unit_by_name_unsafe(e->output_name); 246 263 if (output == NULL) { 247 264 sysman_log(LVL_ERROR, … … 273 290 } 274 291 275 unit_t *repo_find_unit_by_name(const char *name) 276 { 277 fibril_rwlock_read_lock(&repo_lock); 278 ht_link_t *ht_link = hash_table_find(&units_by_name, (void *)name); 279 fibril_rwlock_read_unlock(&repo_lock); 280 281 if (ht_link != NULL) { 282 return hash_table_get_inst(ht_link, unit_t, units_by_name); 283 } else { 284 return NULL; 285 } 286 } 287 292 /** 293 * The function can be safely called from non-event loop fibrils 294 */ 295 unit_t *repo_find_unit_by_name_(const char *name) 296 { 297 return repo_find_unit_by_name_internal(name, true); 298 } 299 300 /** 301 * @note Caller must hold repo_lock (at least reader) 302 */ 303 unit_t *repo_find_unit_by_name_unsafe(const char *name) 304 { 305 return repo_find_unit_by_name_internal(name, false); 306 } 307 308 /** 309 * The function can be safely called from non-event loop fibrils 310 */ 288 311 unit_t *repo_find_unit_by_handle(unit_handle_t handle) 289 312 { 313 sysman_log(LVL_DEBUG2, "%s", __func__); 290 314 fibril_rwlock_read_lock(&repo_lock); 291 315 ht_link_t *ht_link = hash_table_find(&units_by_handle, &handle); … … 301 325 void repo_rlock(void) 302 326 { 327 sysman_log(LVL_DEBUG2, "%s", __func__); 303 328 fibril_rwlock_read_lock(&repo_lock); 304 329 } … … 306 331 void repo_runlock(void) 307 332 { 333 sysman_log(LVL_DEBUG2, "%s", __func__); 308 334 fibril_rwlock_read_unlock(&repo_lock); 309 335 }
Note:
See TracChangeset
for help on using the changeset viewer.