diff options
Diffstat (limited to 'src/comp.c')
-rw-r--r-- | src/comp.c | 65 |
1 files changed, 46 insertions, 19 deletions
@@ -24,6 +24,11 @@ struct complist struct component *tail; }; +/* 0 on the first load, and 1 on all subsequent reloads. Tells the + component_config_commit whether we're starting from scratch or just + updating an already loaded configuration */ +static int loaded; + static struct complist comp_list[2]; static int cur; @@ -32,13 +37,13 @@ static size_t comp_count; static pies_depmap_t depmap; -static int +static inline int next_index (void) { return (cur + 1) % ARRAY_SIZE (comp_list); } -static int +static inline int prev_index (void) { return (cur + ARRAY_SIZE (comp_list) - 1) % ARRAY_SIZE (comp_list); @@ -85,6 +90,22 @@ component_append (struct component *comp) } void +comp_array_remove (size_t i) +{ + struct component *comp = comp_array[i]; + + depmap_remove (depmap, i); + while (i < comp_count -1) + { + comp_array[i] = comp_array[i+1]; + comp_array[i]->arridx = i; + i++; + } + component_free (comp); + comp_count--; +} + +void component_unlink (struct component *comp) { struct complist *list = &comp_list[comp->listidx]; @@ -201,8 +222,13 @@ component_ref_decr (struct component *comp) { assert (comp->ref_count > 0); if (--comp->ref_count == 0) + { + if (component_is_active (comp)) + comp_array_remove (comp->arridx); + else component_free (comp); } +} static int argvcmp (char **a, char **b) @@ -425,17 +451,6 @@ report_cyclic_dependency (pies_depmap_t dp, size_t idx) } void -comp_array_remove (size_t i) -{ - struct component *comp = comp_array[i]; - if (i < comp_count - 1) - memmove (&comp_array[i], &comp_array[i+1], - (comp_count - i - 1) * sizeof comp_array[0]); - component_free (comp); - comp_count--; -} - -void component_build_depmap (void) { size_t i; @@ -460,7 +475,6 @@ component_build_depmap (void) "which is not declared"), comp->tag, tag); comp_array_remove (i); - depmap_remove (depmap, i); continue; } depmap_set (depmap, i, tgt); @@ -497,10 +511,7 @@ component_build_depmap (void) for (i = 0; i < comp_count;) if (comp_array[i]->flags & CF_REMOVE) - { comp_array_remove (i); - depmap_remove (depmap, i); - } else i++; @@ -528,8 +539,17 @@ component_config_commit (void) comp_array = grecs_realloc (comp_array, i * sizeof (comp_array[0])); comp_count = i; - /* Rearrange components, registering prog entries for the new ones */ - for (comp = list->head, i = 0; comp; comp = comp->next, i++) + /* Rearrange components, registering entries for the new ones */ + for (comp = list->head, i = 0; comp; ) + { + struct component *next = comp->next; + if (loaded && comp->mode == pies_comp_startup) + { + /* Ignore startup components */ + component_unlink (comp); + component_free (comp); + } + else { match = complist_find_match (prev, comp); if (match) @@ -543,7 +563,12 @@ component_config_commit (void) } comp_array[i] = comp; comp->arridx = i; + i++; + } + comp = next; } + /* Adjust comp_count */ + comp_count = i; /* Mark orphaned progs for termination */ list = &comp_list[prev]; @@ -560,6 +585,8 @@ component_config_commit (void) for (comp = comp_list[cur].head; comp; comp = comp->next) if (!comp->prog) register_prog (comp); + + loaded = 1; } static int |