Changeset 0ca7286 in mainline for uspace/srv/ns/task.c
- Timestamp:
- 2012-07-21T11:19:27Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2732c94
- Parents:
- 1c1da4b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/ns/task.c
r1c1da4b r0ca7286 43 43 #include "ns.h" 44 44 45 #define TASK_HASH_TABLE_CHAINS 25646 #define P2I_HASH_TABLE_CHAINS 25647 45 48 46 /* TODO: … … 71 69 * 72 70 */ 73 static hash_index_t task_hash(unsigned long key[]) 74 { 75 assert(key); 76 return (LOWER32(key[0]) % TASK_HASH_TABLE_CHAINS); 71 static size_t task_key_hash(unsigned long key[]) 72 { 73 size_t hash = 17; 74 hash = 37 * hash + key[1]; 75 hash = 37 * hash + key[0]; 76 return hash; 77 } 78 79 static size_t task_hash(const link_t *item) 80 { 81 hashed_task_t *ht = hash_table_get_instance(item, hashed_task_t, link); 82 83 unsigned long key[] = { 84 LOWER32(ht->id), 85 UPPER32(ht->id) 86 }; 87 88 return task_key_hash(key); 77 89 } 78 90 … … 86 98 * 87 99 */ 88 static int task_compare(unsigned long key[], hash_count_t keys,link_t *item)100 static bool task_match(unsigned long key[], size_t keys, const link_t *item) 89 101 { 90 102 assert(key); 91 assert(keys <= 2);103 assert(keys == 2); 92 104 assert(item); 93 105 94 106 hashed_task_t *ht = hash_table_get_instance(item, hashed_task_t, link); 95 107 96 if (keys == 2) 97 return ((LOWER32(key[1]) == UPPER32(ht->id)) 98 && (LOWER32(key[0]) == LOWER32(ht->id))); 99 else 100 return (LOWER32(key[0]) == LOWER32(ht->id)); 108 return (key[0] == LOWER32(ht->id)) 109 && (key[1] == UPPER32(ht->id)); 101 110 } 102 111 … … 113 122 114 123 /** Operations for task hash table. */ 115 static hash_table_op erations_t task_hash_table_ops = {124 static hash_table_ops_t task_hash_table_ops = { 116 125 .hash = task_hash, 117 .compare = task_compare, 126 .key_hash = task_key_hash, 127 .match = task_match, 128 .equal = 0, 118 129 .remove_callback = task_remove 119 130 }; … … 135 146 * 136 147 */ 137 static hash_index_t p2i_hash(unsigned long key[])148 static size_t p2i_key_hash(unsigned long key[]) 138 149 { 139 150 assert(key); 140 return (key[0] % TASK_HASH_TABLE_CHAINS); 151 return key[0]; 152 } 153 154 static size_t p2i_hash(const link_t *item) 155 { 156 p2i_entry_t *entry = hash_table_get_instance(item, p2i_entry_t, link); 157 unsigned long key = entry->in_phone_hash; 158 return p2i_key_hash(&key); 141 159 } 142 160 … … 150 168 * 151 169 */ 152 static int p2i_compare(unsigned long key[], hash_count_t keys,link_t *item)170 static bool p2i_match(unsigned long key[], size_t keys, const link_t *item) 153 171 { 154 172 assert(key); … … 173 191 174 192 /** Operations for task hash table. */ 175 static hash_table_op erations_t p2i_ops = {193 static hash_table_ops_t p2i_ops = { 176 194 .hash = p2i_hash, 177 .compare = p2i_compare, 195 .key_hash = p2i_key_hash, 196 .match = p2i_match, 197 .equal = 0, 178 198 .remove_callback = p2i_remove 179 199 }; … … 193 213 int task_init(void) 194 214 { 195 if (!hash_table_create(&task_hash_table, TASK_HASH_TABLE_CHAINS, 196 2, &task_hash_table_ops)) { 215 if (!hash_table_create(&task_hash_table, 0, 2, &task_hash_table_ops)) { 197 216 printf(NAME ": No memory available for tasks\n"); 198 217 return ENOMEM; 199 218 } 200 219 201 if (!hash_table_create(&phone_to_id, P2I_HASH_TABLE_CHAINS, 202 1, &p2i_ops)) { 220 if (!hash_table_create(&phone_to_id, 0, 1, &p2i_ops)) { 203 221 printf(NAME ": No memory available for tasks\n"); 204 222 return ENOMEM; … … 293 311 int ns_task_id_intro(ipc_call_t *call) 294 312 { 295 unsigned long keys[2];296 313 297 314 task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); 298 keys[0] = call->in_phone_hash; 315 316 unsigned long keys[] = { call->in_phone_hash }; 299 317 300 318 link_t *link = hash_table_find(&phone_to_id, keys); … … 317 335 entry->in_phone_hash = call->in_phone_hash; 318 336 entry->id = id; 319 hash_table_insert(&phone_to_id, keys,&entry->link);337 hash_table_insert(&phone_to_id, &entry->link); 320 338 321 339 /* 322 340 * Insert into the main table. 323 341 */ 324 325 keys[0] = LOWER32(id);326 keys[1] = UPPER32(id);327 342 328 343 link_initialize(&ht->link); … … 331 346 ht->have_rval = false; 332 347 ht->retval = -1; 333 hash_table_insert(&task_hash_table, keys,&ht->link);348 hash_table_insert(&task_hash_table, &ht->link); 334 349 335 350 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.