Changeset 61eb2ce2 in mainline for uspace


Ignore:
Timestamp:
2023-02-05T22:03:19Z (3 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:
uspace
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • 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.