Changeset 9f4067b6 in mainline for uspace/lib/nic/src/nic_wol_virtues.c
- Timestamp:
- 2012-10-09T21:16:13Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6659037, 7d248e3
- Parents:
- d1ef4a1 (diff), 97b199b1 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/nic/src/nic_wol_virtues.c
rd1ef4a1 r9f4067b6 37 37 38 38 #include "nic_wol_virtues.h" 39 #include "nic.h" 39 40 #include <assert.h> 40 41 #include <errno.h> 41 42 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 48 static size_t nic_wv_key_hash(void *key) 49 { 50 return *(nic_wv_id_t*) key; 51 } 52 53 static size_t nic_wv_hash(const ht_link_t *item) 49 54 { 50 55 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 59 static 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); 67 63 } 68 64 … … 77 73 int nic_wol_virtues_init(nic_wol_virtues_t *wvs) 78 74 { 79 bzero(wvs, sizeof (nic_wol_virtues_t)); 80 wvs->table_operations.compare = nic_wv_compare; 75 bzero(wvs, sizeof(nic_wol_virtues_t)); 81 76 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)) { 85 83 return ENOMEM; 86 84 } … … 170 168 do { 171 169 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); 176 172 virtue->next = wvs->lists[virtue->type]; 177 173 wvs->lists[virtue->type] = virtue; … … 191 187 nic_wol_virtue_t *nic_wol_virtues_remove(nic_wol_virtues_t *wvs, nic_wv_id_t id) 192 188 { 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); 195 191 if (virtue == NULL) { 196 192 return NULL; … … 198 194 199 195 /* Remove from filter_table */ 200 hash_table_remove (&wvs->table, (unsigned long *) &id, 1);196 hash_table_remove_item(&wvs->table, &virtue->item); 201 197 202 198 /* Remove from filter_types */ … … 235 231 * constant virtue the retyping is correct. 236 232 */ 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); 239 234 return (const nic_wol_virtue_t *) virtue; 240 235 }
Note:
See TracChangeset
for help on using the changeset viewer.