Changeset 61eb2ce2 in mainline for kernel/generic/src


Ignore:
Timestamp:
2023-02-05T22:03:19Z (2 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b596d0d
Parents:
07700ed
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-05 22:01:46)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-05 22:03:19)
Message:

Make hash table operations immutable, because global mutable state is evil

Location:
kernel/generic/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/adt/hash_table.c

    r07700ed r61eb2ce2  
    9090 */
    9191bool hash_table_create(hash_table_t *h, size_t init_size, size_t max_load,
    92     hash_table_ops_t *op)
     92    const hash_table_ops_t *op)
    9393{
    9494        assert(h);
     
    110110        h->apply_ongoing = false;
    111111
    112         if (h->op->remove_callback == NULL) {
    113                 h->op->remove_callback = nop_remove_callback;
    114         }
    115 
    116112        return true;
    117113}
     
    171167        if (h->item_cnt == 0)
    172168                return;
     169
     170        void (*remove_cb)(ht_link_t *) = h->op->remove_callback ? h->op->remove_callback : nop_remove_callback;
    173171
    174172        for (size_t idx = 0; idx < h->bucket_cnt; ++idx) {
     
    178176
    179177                        list_remove(cur);
    180                         h->op->remove_callback(cur_link);
     178                        remove_cb(cur_link);
    181179                }
    182180        }
     
    321319                        ++removed;
    322320                        list_remove(cur);
    323                         h->op->remove_callback(cur_link);
     321
     322                        if (h->op->remove_callback)
     323                                h->op->remove_callback(cur_link);
    324324                }
    325325        }
     
    340340        list_remove(&item->link);
    341341        --h->item_cnt;
    342         h->op->remove_callback(item);
     342
     343        if (h->op->remove_callback)
     344                h->op->remove_callback(item);
    343345        shrink_if_needed(h);
    344346}
  • kernel/generic/src/cap/cap.c

    r07700ed r61eb2ce2  
    125125}
    126126
    127 static hash_table_ops_t caps_ops = {
     127static const hash_table_ops_t caps_ops = {
    128128        .hash = caps_hash,
    129129        .key_hash = caps_key_hash,
  • kernel/generic/src/ddi/irq.c

    r07700ed r61eb2ce2  
    7777static bool irq_ht_key_equal(const void *, const ht_link_t *);
    7878
    79 static hash_table_ops_t irq_ht_ops = {
     79static const hash_table_ops_t irq_ht_ops = {
    8080        .hash = irq_ht_hash,
    8181        .key_hash = irq_ht_key_hash,
  • kernel/generic/src/lib/ra.c

    r07700ed r61eb2ce2  
    8181}
    8282
    83 static hash_table_ops_t used_ops = {
     83static const hash_table_ops_t used_ops = {
    8484        .hash = used_hash,
    8585        .key_hash = used_key_hash,
  • kernel/generic/src/mm/as.c

    r07700ed r61eb2ce2  
    8686 * address space operations such as creating or locking page tables.
    8787 */
    88 as_operations_t *as_operations = NULL;
     88const as_operations_t *as_operations = NULL;
    8989
    9090/** Cache for as_t objects */
  • kernel/generic/src/mm/page.c

    r07700ed r61eb2ce2  
    7676
    7777/** Virtual operations for page subsystem. */
    78 page_mapping_operations_t *page_mapping_operations = NULL;
     78const page_mapping_operations_t *page_mapping_operations = NULL;
    7979
    8080void page_init(void)
Note: See TracChangeset for help on using the changeset viewer.