Changeset 0ca7286 in mainline for uspace/srv/ns/service.c


Ignore:
Timestamp:
2012-07-21T11:19:27Z (12 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2732c94
Parents:
1c1da4b
Message:

Added resizing to user space (single-threaded) hash_table. Resizes in a way to mitigate effects of bad hash functions. Change of interface affected many files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/ns/service.c

    r1c1da4b r0ca7286  
    4040#include "ns.h"
    4141
    42 #define SERVICE_HASH_TABLE_CHAINS  20
    4342
    4443/** Service hash table item. */
     
    5857 *
    5958 */
    60 static hash_index_t service_hash(unsigned long key[])
     59static size_t service_key_hash(unsigned long key[])
    6160{
    6261        assert(key);
    63         return (key[0] % SERVICE_HASH_TABLE_CHAINS);
     62        return key[0];
     63}
     64
     65static size_t service_hash(const link_t *item)
     66{
     67        hashed_service_t *hs = hash_table_get_instance(item, hashed_service_t, link);
     68        unsigned long key = hs->service;
     69        return service_key_hash(&key);
    6470}
    6571
     
    7985 *
    8086 */
    81 static int service_compare(unsigned long key[], hash_count_t keys, link_t *item)
     87static bool service_match(unsigned long key[], size_t keys, const link_t *item)
    8288{
    8389        assert(key);
     
    105111
    106112/** Operations for service hash table. */
    107 static hash_table_operations_t service_hash_table_ops = {
     113static hash_table_ops_t service_hash_table_ops = {
    108114        .hash = service_hash,
    109         .compare = service_compare,
     115        .key_hash = service_key_hash,
     116        .match = service_match,
     117        .equal = 0,
    110118        .remove_callback = service_remove
    111119};
     
    127135int service_init(void)
    128136{
    129         if (!hash_table_create(&service_hash_table, SERVICE_HASH_TABLE_CHAINS,
    130             3, &service_hash_table_ops)) {
     137        if (!hash_table_create(&service_hash_table, 0, 3, &service_hash_table_ops)) {
    131138                printf(NAME ": No memory available for services\n");
    132139                return ENOMEM;
     
    193200        hs->phone = phone;
    194201        hs->in_phone_hash = call->in_phone_hash;
    195         hash_table_insert(&service_hash_table, keys, &hs->link);
     202        hash_table_insert(&service_hash_table, &hs->link);
    196203       
    197204        return EOK;
Note: See TracChangeset for help on using the changeset viewer.