Changeset efdfebc in mainline for uspace/lib/nic/src/nic_wol_virtues.c


Ignore:
Timestamp:
2012-11-06T21:03:44Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
338810f
Parents:
de73242 (diff), 94795812 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/nic/src/nic_wol_virtues.c

    rde73242 refdfebc  
    3737
    3838#include "nic_wol_virtues.h"
     39#include "nic.h"
    3940#include <assert.h>
    4041#include <errno.h>
    4142
    42 #define NIC_WV_HASH_COUNT 32
    43 
    44 /**
    45  * Hash table helper function
    46  */
    47 static int nic_wv_compare(unsigned long key[], hash_count_t keys,
    48         link_t *item)
     43
     44/*
     45 * Hash table helper functions
     46 */
     47
     48static size_t nic_wv_key_hash(void *key)
     49{
     50        return *(nic_wv_id_t*) key;
     51}
     52
     53static size_t nic_wv_hash(const ht_link_t *item)
    4954{
    5055        nic_wol_virtue_t *virtue = (nic_wol_virtue_t *) item;
    51         return (virtue->id == (nic_wv_id_t) key[0]);
    52 }
    53 
    54 /**
    55  * Hash table helper function
    56  */
    57 static void nic_wv_rc(link_t *item)
    58 {
    59 }
    60 
    61 /**
    62  * Hash table helper function
    63  */
    64 static hash_index_t nic_wv_hash(unsigned long keys[])
    65 {
    66         return keys[0] % NIC_WV_HASH_COUNT;
     56        return virtue->id;
     57}
     58
     59static bool nic_wv_key_equal(void *key, const ht_link_t *item)
     60{
     61        nic_wol_virtue_t *virtue = (nic_wol_virtue_t *) item;
     62        return (virtue->id == *(nic_wv_id_t*) key);
    6763}
    6864
     
    7773int nic_wol_virtues_init(nic_wol_virtues_t *wvs)
    7874{
    79         bzero(wvs, sizeof (nic_wol_virtues_t));
    80         wvs->table_operations.compare = nic_wv_compare;
     75        bzero(wvs, sizeof(nic_wol_virtues_t));
    8176        wvs->table_operations.hash = nic_wv_hash;
    82         wvs->table_operations.remove_callback = nic_wv_rc;
    83         if (!hash_table_create(&wvs->table, NIC_WV_HASH_COUNT, 1,
    84                 &wvs->table_operations)) {
     77        wvs->table_operations.key_hash = nic_wv_key_hash;
     78        wvs->table_operations.key_equal = nic_wv_key_equal;
     79        wvs->table_operations.equal = 0;
     80        wvs->table_operations.remove_callback = 0;
     81       
     82        if (!hash_table_create(&wvs->table, 0, 0, &wvs->table_operations)) {
    8583                return ENOMEM;
    8684        }
     
    170168        do {
    171169                virtue->id = wvs->next_id++;
    172         } while (NULL !=
    173                 hash_table_find(&wvs->table, (unsigned long *) &virtue->id));
    174         hash_table_insert(&wvs->table,
    175                 (unsigned long *) &virtue->id, &virtue->item);
     170        } while (NULL != hash_table_find(&wvs->table, &virtue->id));
     171        hash_table_insert(&wvs->table, &virtue->item);
    176172        virtue->next = wvs->lists[virtue->type];
    177173        wvs->lists[virtue->type] = virtue;
     
    191187nic_wol_virtue_t *nic_wol_virtues_remove(nic_wol_virtues_t *wvs, nic_wv_id_t id)
    192188{
    193         nic_wol_virtue_t *virtue = (nic_wol_virtue_t *)
    194                 hash_table_find(&wvs->table, (unsigned long *) &id);
     189        nic_wol_virtue_t *virtue =
     190                (nic_wol_virtue_t *) hash_table_find(&wvs->table, &id);
    195191        if (virtue == NULL) {
    196192                return NULL;
     
    198194
    199195        /* Remove from filter_table */
    200         hash_table_remove(&wvs->table, (unsigned long *) &id, 1);
     196        hash_table_remove_item(&wvs->table, &virtue->item);
    201197
    202198        /* Remove from filter_types */
     
    235231         * constant virtue the retyping is correct.
    236232         */
    237         link_t *virtue = hash_table_find(
    238                 &((nic_wol_virtues_t *) wvs)->table, (unsigned long *) &id);
     233        ht_link_t *virtue = hash_table_find(&((nic_wol_virtues_t *) wvs)->table, &id);
    239234        return (const nic_wol_virtue_t *) virtue;
    240235}
Note: See TracChangeset for help on using the changeset viewer.