Changeset ad7a6c9 in mainline for uspace/srv/ns/task.c
- Timestamp:
- 2011-03-30T13:10:24Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4ae90f9
- Parents:
- 6e50466 (diff), d6b81941 (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/srv/ns/task.c
r6e50466 rad7a6c9 43 43 44 44 #define TASK_HASH_TABLE_CHAINS 256 45 #define P2I_HASH_TABLE_CHAINS 256 46 47 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id); 45 #define P2I_HASH_TABLE_CHAINS 256 48 46 49 47 /* TODO: … … 57 55 typedef struct { 58 56 link_t link; 59 task_id_t id; /**< Task ID. */ 60 bool finished; /**< Task is done. */ 61 bool have_rval; /**< Task returned a value. */ 62 int retval; /**< The return value. */ 57 58 task_id_t id; /**< Task ID. */ 59 bool finished; /**< Task is done. */ 60 bool have_rval; /**< Task returned a value. */ 61 int retval; /**< The return value. */ 63 62 } hashed_task_t; 64 63 … … 71 70 * 72 71 */ 73 static hash_index_t task_hash(unsigned long *key)72 static hash_index_t task_hash(unsigned long key[]) 74 73 { 75 74 assert(key); 76 return (LOWER32( *key) % TASK_HASH_TABLE_CHAINS);75 return (LOWER32(key[0]) % TASK_HASH_TABLE_CHAINS); 77 76 } 78 77 … … 124 123 typedef struct { 125 124 link_t link; 126 sysarg_t phash; /**< Task ID. */127 task_id_t id; /**< Task ID. */125 sysarg_t in_phone_hash; /**< Incoming phone hash. */ 126 task_id_t id; /**< Task ID. */ 128 127 } p2i_entry_t; 129 128 … … 131 130 * 132 131 * @param key Array of keys. 132 * 133 133 * @return Hash index corresponding to key[0]. 134 134 * 135 135 */ 136 static hash_index_t p2i_hash(unsigned long *key)136 static hash_index_t p2i_hash(unsigned long key[]) 137 137 { 138 138 assert(key); 139 return ( *key% TASK_HASH_TABLE_CHAINS);139 return (key[0] % TASK_HASH_TABLE_CHAINS); 140 140 } 141 141 … … 154 154 assert(keys == 1); 155 155 assert(item); 156 157 p2i_entry_t *e = hash_table_get_instance(item, p2i_entry_t, link);158 159 return (key[0] == e ->phash);156 157 p2i_entry_t *entry = hash_table_get_instance(item, p2i_entry_t, link); 158 159 return (key[0] == entry->in_phone_hash); 160 160 } 161 161 … … 197 197 return ENOMEM; 198 198 } 199 199 200 200 if (!hash_table_create(&phone_to_id, P2I_HASH_TABLE_CHAINS, 201 201 1, &p2i_ops)) { … … 205 205 206 206 list_initialize(&pending_wait); 207 208 207 return EOK; 209 208 } … … 238 237 ht->retval); 239 238 } 240 239 241 240 hash_table_remove(&task_hash_table, keys, 2); 242 241 list_remove(cur); … … 250 249 sysarg_t retval; 251 250 task_exit_t texit; 252 251 253 252 unsigned long keys[2] = { 254 253 LOWER32(id), 255 254 UPPER32(id) 256 255 }; 257 256 258 257 link_t *link = hash_table_find(&task_hash_table, keys); 259 258 hashed_task_t *ht = (link != NULL) ? 260 259 hash_table_get_instance(link, hashed_task_t, link) : NULL; 261 260 262 261 if (ht == NULL) { 263 262 /* No such task exists. */ … … 265 264 return; 266 265 } 267 266 268 267 if (!ht->finished) { 269 268 /* Add to pending list */ … … 275 274 } 276 275 276 link_initialize(&pr->link); 277 277 pr->id = id; 278 278 pr->callid = callid; … … 293 293 int ns_task_id_intro(ipc_call_t *call) 294 294 { 295 task_id_t id;296 295 unsigned long keys[2]; 297 link_t *link; 298 p2i_entry_t *e; 299 hashed_task_t *ht; 300 301 id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); 302 296 297 task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); 303 298 keys[0] = call->in_phone_hash; 304 305 link = hash_table_find(&phone_to_id, keys);299 300 link_t *link = hash_table_find(&phone_to_id, keys); 306 301 if (link != NULL) 307 302 return EEXISTS; 308 309 e= (p2i_entry_t *) malloc(sizeof(p2i_entry_t));310 if (e == NULL)303 304 p2i_entry_t *entry = (p2i_entry_t *) malloc(sizeof(p2i_entry_t)); 305 if (entry == NULL) 311 306 return ENOMEM; 312 313 h t = (hashed_task_t *) malloc(sizeof(hashed_task_t));307 308 hashed_task_t *ht = (hashed_task_t *) malloc(sizeof(hashed_task_t)); 314 309 if (ht == NULL) 315 310 return ENOMEM; 316 317 /* Insert to phone-to-id map. */ 318 319 link_initialize(&e->link); 320 e->phash = call->in_phone_hash; 321 e->id = id; 322 hash_table_insert(&phone_to_id, keys, &e->link); 323 324 /* Insert to main table. */ 325 311 312 /* 313 * Insert into the phone-to-id map. 314 */ 315 316 link_initialize(&entry->link); 317 entry->in_phone_hash = call->in_phone_hash; 318 entry->id = id; 319 hash_table_insert(&phone_to_id, keys, &entry->link); 320 321 /* 322 * Insert into the main table. 323 */ 324 326 325 keys[0] = LOWER32(id); 327 326 keys[1] = UPPER32(id); 328 327 329 328 link_initialize(&ht->link); 330 329 ht->id = id; … … 333 332 ht->retval = -1; 334 333 hash_table_insert(&task_hash_table, keys, &ht->link); 335 334 336 335 return EOK; 337 336 } 338 337 338 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id) 339 { 340 unsigned long keys[1] = {phone_hash}; 341 342 link_t *link = hash_table_find(&phone_to_id, keys); 343 if (link == NULL) 344 return ENOENT; 345 346 p2i_entry_t *entry = hash_table_get_instance(link, p2i_entry_t, link); 347 *id = entry->id; 348 349 return EOK; 350 } 351 339 352 int ns_task_retval(ipc_call_t *call) 340 353 { 341 354 task_id_t id; 342 unsigned long keys[2]; 343 int rc; 344 345 rc = get_id_by_phone(call->in_phone_hash, &id); 355 int rc = get_id_by_phone(call->in_phone_hash, &id); 346 356 if (rc != EOK) 347 357 return rc; 348 349 keys[0] = LOWER32(id); 350 keys[1] = UPPER32(id); 358 359 unsigned long keys[2] = { 360 LOWER32(id), 361 UPPER32(id) 362 }; 351 363 352 364 link_t *link = hash_table_find(&task_hash_table, keys); … … 354 366 hash_table_get_instance(link, hashed_task_t, link) : NULL; 355 367 356 if ((ht == NULL) || ht->finished)368 if ((ht == NULL) || (ht->finished)) 357 369 return EINVAL; 358 370 359 371 ht->finished = true; 360 372 ht->have_rval = true; 361 373 ht->retval = IPC_GET_ARG1(*call); 362 374 363 375 return EOK; 364 376 } … … 367 379 { 368 380 unsigned long keys[2]; 381 369 382 task_id_t id; 370 int rc; 371 372 rc = get_id_by_phone(call->in_phone_hash, &id); 383 int rc = get_id_by_phone(call->in_phone_hash, &id); 373 384 if (rc != EOK) 374 385 return rc; 375 386 376 387 /* Delete from phone-to-id map. */ 377 388 keys[0] = call->in_phone_hash; 378 389 hash_table_remove(&phone_to_id, keys, 1); 379 390 380 391 /* Mark task as finished. */ 381 392 keys[0] = LOWER32(id); 382 393 keys[1] = UPPER32(id); 383 394 384 395 link_t *link = hash_table_find(&task_hash_table, keys); 385 396 hashed_task_t *ht = … … 387 398 if (ht == NULL) 388 399 return EOK; 389 400 390 401 ht->finished = true; 391 392 return EOK; 393 } 394 395 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id) 396 { 397 unsigned long keys[1]; 398 link_t *link; 399 p2i_entry_t *e; 400 401 keys[0] = phone_hash; 402 link = hash_table_find(&phone_to_id, keys); 403 if (link == NULL) 404 return ENOENT; 405 406 e = hash_table_get_instance(link, p2i_entry_t, link); 407 *id = e->id; 408 402 409 403 return EOK; 410 404 }
Note:
See TracChangeset
for help on using the changeset viewer.