Changeset 61eb2ce2 in mainline


Ignore:
Timestamp:
2023-02-05T22:03:19Z (16 months 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

Files:
37 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/include/genarch/mm/page_ht.h

    r07700ed r61eb2ce2  
    5757#define PTE_EXECUTABLE(pte)  ((pte)->x != 0)
    5858
    59 extern as_operations_t as_ht_operations;
    60 extern page_mapping_operations_t ht_mapping_operations;
     59extern const as_operations_t as_ht_operations;
     60extern const page_mapping_operations_t ht_mapping_operations;
    6161
    6262extern slab_cache_t *pte_cache;
    6363extern hash_table_t page_ht;
    64 extern hash_table_ops_t ht_ops;
     64extern const hash_table_ops_t ht_ops;
    6565
    6666#endif
  • kernel/genarch/include/genarch/mm/page_pt.h

    r07700ed r61eb2ce2  
    140140#define PTE_EXECUTABLE(p)  PTE_EXECUTABLE_ARCH((p))
    141141
    142 extern as_operations_t as_pt_operations;
    143 extern page_mapping_operations_t pt_mapping_operations;
     142extern const as_operations_t as_pt_operations;
     143extern const page_mapping_operations_t pt_mapping_operations;
    144144
    145145extern void page_mapping_insert_pt(as_t *, uintptr_t, uintptr_t, unsigned int);
  • kernel/genarch/src/mm/as_ht.c

    r07700ed r61eb2ce2  
    5353static bool ht_locked(as_t *);
    5454
    55 as_operations_t as_ht_operations = {
     55const as_operations_t as_ht_operations = {
    5656        .page_table_create = ht_create,
    5757        .page_table_destroy = ht_destroy,
  • kernel/genarch/src/mm/as_pt.c

    r07700ed r61eb2ce2  
    5454static bool pt_locked(as_t *);
    5555
    56 as_operations_t as_pt_operations = {
     56const as_operations_t as_pt_operations = {
    5757        .page_table_create = ptl0_create,
    5858        .page_table_destroy = ptl0_destroy,
  • kernel/genarch/src/mm/page_ht.c

    r07700ed r61eb2ce2  
    8282
    8383/** Hash table operations for page hash table. */
    84 hash_table_ops_t ht_ops = {
     84const hash_table_ops_t ht_ops = {
    8585        .hash = ht_hash,
    8686        .key_hash = ht_key_hash,
     
    9090
    9191/** Page mapping operations for page hash table architectures. */
    92 page_mapping_operations_t ht_mapping_operations = {
     92const page_mapping_operations_t ht_mapping_operations = {
    9393        .mapping_insert = ht_mapping_insert,
    9494        .mapping_remove = ht_mapping_remove,
  • kernel/genarch/src/mm/page_pt.c

    r07700ed r61eb2ce2  
    5858static void pt_mapping_make_global(uintptr_t, size_t);
    5959
    60 page_mapping_operations_t pt_mapping_operations = {
     60const page_mapping_operations_t pt_mapping_operations = {
    6161        .mapping_insert = pt_mapping_insert,
    6262        .mapping_remove = pt_mapping_remove,
  • kernel/generic/include/adt/hash_table.h

    r07700ed r61eb2ce2  
    7373/** Hash table structure. */
    7474typedef struct {
    75         hash_table_ops_t *op;
     75        const hash_table_ops_t *op;
    7676        list_t *bucket;
    7777        size_t bucket_cnt;
     
    8686
    8787extern bool hash_table_create(hash_table_t *, size_t, size_t,
    88     hash_table_ops_t *);
     88    const hash_table_ops_t *);
    8989extern void hash_table_destroy(hash_table_t *);
    9090
  • kernel/generic/include/mm/as.h

    r07700ed r61eb2ce2  
    307307extern as_t *AS_KERNEL;
    308308
    309 extern as_operations_t *as_operations;
     309extern const as_operations_t *as_operations;
    310310extern list_t inactive_as_with_asid_list;
    311311
  • kernel/generic/include/mm/page.h

    r07700ed r61eb2ce2  
    5353} page_mapping_operations_t;
    5454
    55 extern page_mapping_operations_t *page_mapping_operations;
     55extern const page_mapping_operations_t *page_mapping_operations;
    5656
    5757extern void page_init(void);
  • 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)
  • uspace/app/hbench/env.c

    r07700ed r61eb2ce2  
    8181}
    8282
    83 static hash_table_ops_t param_hash_table_ops = {
     83static const hash_table_ops_t param_hash_table_ops = {
    8484        .hash = param_hash,
    8585        .key_hash = param_key_hash,
  • uspace/app/trace/ipcp.c

    r07700ed r61eb2ce2  
    9292}
    9393
    94 static hash_table_ops_t pending_call_ops = {
     94static const hash_table_ops_t pending_call_ops = {
    9595        .hash = pending_call_hash,
    9696        .key_hash = pending_call_key_hash,
  • uspace/app/trace/proto.c

    r07700ed r61eb2ce2  
    7676}
    7777
    78 static hash_table_ops_t srv_proto_ops = {
     78static const hash_table_ops_t srv_proto_ops = {
    7979        .hash = srv_proto_hash,
    8080        .key_hash = srv_proto_key_hash,
     
    103103}
    104104
    105 static hash_table_ops_t method_oper_ops = {
     105static const hash_table_ops_t method_oper_ops = {
    106106        .hash = method_oper_hash,
    107107        .key_hash = method_oper_key_hash,
  • uspace/lib/block/block.c

    r07700ed r61eb2ce2  
    260260}
    261261
    262 static hash_table_ops_t cache_ops = {
     262static const hash_table_ops_t cache_ops = {
    263263        .hash = cache_hash,
    264264        .key_hash = cache_key_hash,
  • uspace/lib/c/generic/adt/hash_table.c

    r07700ed r61eb2ce2  
    9191 */
    9292bool hash_table_create(hash_table_t *h, size_t init_size, size_t max_load,
    93     hash_table_ops_t *op)
     93    const hash_table_ops_t *op)
    9494{
    9595        assert(h);
     
    111111        h->apply_ongoing = false;
    112112
    113         if (h->op->remove_callback == NULL) {
    114                 h->op->remove_callback = nop_remove_callback;
    115         }
    116 
    117113        return true;
    118114}
     
    172168        if (h->item_cnt == 0)
    173169                return;
     170
     171        void (*remove_cb)(ht_link_t *) = h->op->remove_callback ? h->op->remove_callback : nop_remove_callback;
    174172
    175173        for (size_t idx = 0; idx < h->bucket_cnt; ++idx) {
     
    179177
    180178                        list_remove(cur);
    181                         h->op->remove_callback(cur_link);
     179                        remove_cb(cur_link);
    182180                }
    183181        }
     
    322320                        ++removed;
    323321                        list_remove(cur);
    324                         h->op->remove_callback(cur_link);
     322
     323                        if (h->op->remove_callback)
     324                                h->op->remove_callback(cur_link);
    325325                }
    326326        }
     
    341341        list_remove(&item->link);
    342342        --h->item_cnt;
    343         h->op->remove_callback(item);
     343
     344        if (h->op->remove_callback)
     345                h->op->remove_callback(item);
    344346        shrink_if_needed(h);
    345347}
  • uspace/lib/c/generic/async/ports.c

    r07700ed r61eb2ce2  
    123123
    124124/** Operations for the port hash table. */
    125 static hash_table_ops_t interface_hash_table_ops = {
     125static const hash_table_ops_t interface_hash_table_ops = {
    126126        .hash = interface_hash,
    127127        .key_hash = interface_key_hash,
     
    151151
    152152/** Operations for the port hash table. */
    153 static hash_table_ops_t port_hash_table_ops = {
     153static const hash_table_ops_t port_hash_table_ops = {
    154154        .hash = port_hash,
    155155        .key_hash = port_key_hash,
  • uspace/lib/c/generic/async/server.c

    r07700ed r61eb2ce2  
    250250
    251251/** Operations for the client hash table. */
    252 static hash_table_ops_t client_hash_table_ops = {
     252static const hash_table_ops_t client_hash_table_ops = {
    253253        .hash = client_hash,
    254254        .key_hash = client_key_hash,
     
    511511
    512512/** Operations for the notification hash table. */
    513 static hash_table_ops_t notification_hash_table_ops = {
     513static const hash_table_ops_t notification_hash_table_ops = {
    514514        .hash = notification_hash,
    515515        .key_hash = notification_key_hash,
  • uspace/lib/c/include/adt/hash_table.h

    r07700ed r61eb2ce2  
    7373/** Hash table structure. */
    7474typedef struct {
    75         hash_table_ops_t *op;
     75        const hash_table_ops_t *op;
    7676        list_t *bucket;
    7777        size_t bucket_cnt;
     
    8686
    8787extern bool hash_table_create(hash_table_t *, size_t, size_t,
    88     hash_table_ops_t *);
     88    const hash_table_ops_t *);
    8989extern void hash_table_destroy(hash_table_t *);
    9090
  • uspace/lib/ext4/src/ops.c

    r07700ed r61eb2ce2  
    122122}
    123123
    124 static hash_table_ops_t open_nodes_ops = {
     124static const hash_table_ops_t open_nodes_ops = {
    125125        .hash = open_nodes_hash,
    126126        .key_hash = open_nodes_key_hash,
  • uspace/lib/nic/src/nic_addr_db.c

    r07700ed r61eb2ce2  
    102102}
    103103
    104 static hash_table_ops_t set_ops = {
     104static const hash_table_ops_t set_ops = {
    105105        .hash = nic_addr_hash,
    106106        .key_hash = nic_addr_key_hash,
  • uspace/srv/devman/devtree.c

    r07700ed r61eb2ce2  
    9393}
    9494
    95 static hash_table_ops_t devman_devices_ops = {
     95static const hash_table_ops_t devman_devices_ops = {
    9696        .hash = devman_devices_hash,
    9797        .key_hash = handle_key_hash,
     
    101101};
    102102
    103 static hash_table_ops_t devman_functions_ops = {
     103static const hash_table_ops_t devman_functions_ops = {
    104104        .hash = devman_functions_hash,
    105105        .key_hash = handle_key_hash,
     
    109109};
    110110
    111 static hash_table_ops_t loc_devices_ops = {
     111static const hash_table_ops_t loc_devices_ops = {
    112112        .hash = loc_functions_hash,
    113113        .key_hash = service_id_key_hash,
  • uspace/srv/fs/cdfs/cdfs_ops.c

    r07700ed r61eb2ce2  
    323323
    324324/** Nodes hash table operations */
    325 static hash_table_ops_t nodes_ops = {
     325static const hash_table_ops_t nodes_ops = {
    326326        .hash = nodes_hash,
    327327        .key_hash = nodes_key_hash,
  • uspace/srv/fs/exfat/exfat_idx.c

    r07700ed r61eb2ce2  
    149149}
    150150
    151 static hash_table_ops_t uph_ops = {
     151static const hash_table_ops_t uph_ops = {
    152152        .hash = pos_hash,
    153153        .key_hash = pos_key_hash,
     
    195195}
    196196
    197 static hash_table_ops_t uih_ops = {
     197static const hash_table_ops_t uih_ops = {
    198198        .hash = idx_hash,
    199199        .key_hash = idx_key_hash,
  • uspace/srv/fs/fat/fat_idx.c

    r07700ed r61eb2ce2  
    149149}
    150150
    151 static hash_table_ops_t uph_ops = {
     151static const hash_table_ops_t uph_ops = {
    152152        .hash = pos_hash,
    153153        .key_hash = pos_key_hash,
     
    195195}
    196196
    197 static hash_table_ops_t uih_ops = {
     197static const hash_table_ops_t uih_ops = {
    198198        .hash = idx_hash,
    199199        .key_hash = idx_key_hash,
  • uspace/srv/fs/locfs/locfs_ops.c

    r07700ed r61eb2ce2  
    9595}
    9696
    97 static hash_table_ops_t services_ops = {
     97static const hash_table_ops_t services_ops = {
    9898        .hash = services_hash,
    9999        .key_hash = services_key_hash,
  • uspace/srv/fs/mfs/mfs_ops.c

    r07700ed r61eb2ce2  
    123123}
    124124
    125 static hash_table_ops_t open_nodes_ops = {
     125static const hash_table_ops_t open_nodes_ops = {
    126126        .hash = open_nodes_hash,
    127127        .key_hash = open_nodes_key_hash,
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r07700ed r61eb2ce2  
    189189
    190190/** TMPFS nodes hash table operations. */
    191 hash_table_ops_t nodes_ops = {
     191const hash_table_ops_t nodes_ops = {
    192192        .hash = nodes_hash,
    193193        .key_hash = nodes_key_hash,
  • uspace/srv/fs/udf/udf_idx.c

    r07700ed r61eb2ce2  
    7878}
    7979
    80 static hash_table_ops_t udf_idx_ops = {
     80static const hash_table_ops_t udf_idx_ops = {
    8181        .hash = udf_idx_hash,
    8282        .key_hash = udf_idx_key_hash,
  • uspace/srv/hid/input/gsp.c

    r07700ed r61eb2ce2  
    8484}
    8585
    86 static hash_table_ops_t trans_ops = {
     86static const hash_table_ops_t trans_ops = {
    8787        .hash = trans_hash,
    8888        .key_hash = trans_key_hash,
  • uspace/srv/ns/service.c

    r07700ed r61eb2ce2  
    112112
    113113/** Operations for service hash table. */
    114 static hash_table_ops_t service_hash_table_ops = {
     114static const hash_table_ops_t service_hash_table_ops = {
    115115        .hash = service_hash,
    116116        .key_hash = service_key_hash,
     
    121121
    122122/** Operations for interface hash table. */
    123 static hash_table_ops_t iface_hash_table_ops = {
     123static const hash_table_ops_t iface_hash_table_ops = {
    124124        .hash = iface_hash,
    125125        .key_hash = iface_key_hash,
  • uspace/srv/ns/task.c

    r07700ed r61eb2ce2  
    8080
    8181/** Operations for task hash table. */
    82 static hash_table_ops_t task_hash_table_ops = {
     82static const hash_table_ops_t task_hash_table_ops = {
    8383        .hash = task_hash,
    8484        .key_hash = task_key_hash,
     
    131131
    132132/** Operations for task hash table. */
    133 static hash_table_ops_t p2i_ops = {
     133static const hash_table_ops_t p2i_ops = {
    134134        .hash = p2i_hash,
    135135        .key_hash = p2i_key_hash,
  • uspace/srv/vfs/vfs_node.c

    r07700ed r61eb2ce2  
    6666
    6767/** VFS node hash table operations. */
    68 hash_table_ops_t nodes_ops = {
     68const hash_table_ops_t nodes_ops = {
    6969        .hash = nodes_hash,
    7070        .key_hash = nodes_key_hash,
Note: See TracChangeset for help on using the changeset viewer.