Changes in uspace/srv/ns/task.c [adb49f58:c7bbf029] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/ns/task.c
radb49f58 rc7bbf029 39 39 #include <stdio.h> 40 40 #include <macros.h> 41 #include <malloc.h> 41 42 #include "task.h" 42 43 #include "ns.h" 43 44 44 45 #define TASK_HASH_TABLE_CHAINS 256 45 #define P2I_HASH_TABLE_CHAINS 256 46 47 static int get_id_by_phone(ipcarg_t phone_hash, task_id_t *id); 46 #define P2I_HASH_TABLE_CHAINS 256 48 47 49 48 /* TODO: … … 57 56 typedef struct { 58 57 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. */ 58 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. */ 63 63 } hashed_task_t; 64 64 … … 71 71 * 72 72 */ 73 static hash_index_t task_hash(unsigned long *key)73 static hash_index_t task_hash(unsigned long key[]) 74 74 { 75 75 assert(key); 76 return (LOWER32( *key) % TASK_HASH_TABLE_CHAINS);76 return (LOWER32(key[0]) % TASK_HASH_TABLE_CHAINS); 77 77 } 78 78 … … 124 124 typedef struct { 125 125 link_t link; 126 ipcarg_t phash; /**< Task ID. */127 task_id_t id; /**< Task ID. */126 sysarg_t in_phone_hash; /**< Incoming phone hash. */ 127 task_id_t id; /**< Task ID. */ 128 128 } p2i_entry_t; 129 129 … … 131 131 * 132 132 * @param key Array of keys. 133 * 133 134 * @return Hash index corresponding to key[0]. 134 135 * 135 136 */ 136 static hash_index_t p2i_hash(unsigned long *key)137 static hash_index_t p2i_hash(unsigned long key[]) 137 138 { 138 139 assert(key); 139 return ( *key% TASK_HASH_TABLE_CHAINS);140 return (key[0] % TASK_HASH_TABLE_CHAINS); 140 141 } 141 142 … … 154 155 assert(keys == 1); 155 156 assert(item); 156 157 p2i_entry_t *e = hash_table_get_instance(item, p2i_entry_t, link);158 159 return (key[0] == e ->phash);157 158 p2i_entry_t *entry = hash_table_get_instance(item, p2i_entry_t, link); 159 160 return (key[0] == entry->in_phone_hash); 160 161 } 161 162 … … 197 198 return ENOMEM; 198 199 } 199 200 200 201 if (!hash_table_create(&phone_to_id, P2I_HASH_TABLE_CHAINS, 201 202 1, &p2i_ops)) { … … 205 206 206 207 list_initialize(&pending_wait); 207 208 208 return EOK; 209 209 } … … 238 238 ht->retval); 239 239 } 240 240 241 241 hash_table_remove(&task_hash_table, keys, 2); 242 242 list_remove(cur); … … 248 248 void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid) 249 249 { 250 ipcarg_t retval;250 sysarg_t retval; 251 251 task_exit_t texit; 252 252 253 253 unsigned long keys[2] = { 254 254 LOWER32(id), 255 255 UPPER32(id) 256 256 }; 257 257 258 258 link_t *link = hash_table_find(&task_hash_table, keys); 259 259 hashed_task_t *ht = (link != NULL) ? 260 260 hash_table_get_instance(link, hashed_task_t, link) : NULL; 261 261 262 262 if (ht == NULL) { 263 263 /* No such task exists. */ 264 retval = ENOENT;265 goto out;266 } 267 264 ipc_answer_0(callid, ENOENT); 265 return; 266 } 267 268 268 if (!ht->finished) { 269 269 /* Add to pending list */ … … 275 275 } 276 276 277 link_initialize(&pr->link); 277 278 pr->id = id; 278 279 pr->callid = callid; … … 293 294 int ns_task_id_intro(ipc_call_t *call) 294 295 { 295 task_id_t id;296 296 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 297 298 task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); 303 299 keys[0] = call->in_phone_hash; 304 305 link = hash_table_find(&phone_to_id, keys);300 301 link_t *link = hash_table_find(&phone_to_id, keys); 306 302 if (link != NULL) 307 303 return EEXISTS; 308 309 e= (p2i_entry_t *) malloc(sizeof(p2i_entry_t));310 if (e == NULL)304 305 p2i_entry_t *entry = (p2i_entry_t *) malloc(sizeof(p2i_entry_t)); 306 if (entry == NULL) 311 307 return ENOMEM; 312 313 h t = (hashed_task_t *) malloc(sizeof(hashed_task_t));308 309 hashed_task_t *ht = (hashed_task_t *) malloc(sizeof(hashed_task_t)); 314 310 if (ht == NULL) 315 311 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 312 313 /* 314 * Insert into the phone-to-id map. 315 */ 316 317 link_initialize(&entry->link); 318 entry->in_phone_hash = call->in_phone_hash; 319 entry->id = id; 320 hash_table_insert(&phone_to_id, keys, &entry->link); 321 322 /* 323 * Insert into the main table. 324 */ 325 326 326 keys[0] = LOWER32(id); 327 327 keys[1] = UPPER32(id); 328 328 329 329 link_initialize(&ht->link); 330 330 ht->id = id; … … 333 333 ht->retval = -1; 334 334 hash_table_insert(&task_hash_table, keys, &ht->link); 335 335 336 336 return EOK; 337 337 } 338 338 339 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id) 340 { 341 unsigned long keys[1] = {phone_hash}; 342 343 link_t *link = hash_table_find(&phone_to_id, keys); 344 if (link == NULL) 345 return ENOENT; 346 347 p2i_entry_t *entry = hash_table_get_instance(link, p2i_entry_t, link); 348 *id = entry->id; 349 350 return EOK; 351 } 352 339 353 int ns_task_retval(ipc_call_t *call) 340 354 { 341 355 task_id_t id; 342 unsigned long keys[2]; 343 int rc; 344 345 rc = get_id_by_phone(call->in_phone_hash, &id); 356 int rc = get_id_by_phone(call->in_phone_hash, &id); 346 357 if (rc != EOK) 347 358 return rc; 348 349 keys[0] = LOWER32(id); 350 keys[1] = UPPER32(id); 359 360 unsigned long keys[2] = { 361 LOWER32(id), 362 UPPER32(id) 363 }; 351 364 352 365 link_t *link = hash_table_find(&task_hash_table, keys); … … 354 367 hash_table_get_instance(link, hashed_task_t, link) : NULL; 355 368 356 if ((ht == NULL) || ht->finished)369 if ((ht == NULL) || (ht->finished)) 357 370 return EINVAL; 358 371 359 372 ht->finished = true; 360 373 ht->have_rval = true; 361 374 ht->retval = IPC_GET_ARG1(*call); 362 375 363 376 return EOK; 364 377 } … … 367 380 { 368 381 unsigned long keys[2]; 382 369 383 task_id_t id; 370 int rc; 371 372 rc = get_id_by_phone(call->in_phone_hash, &id); 384 int rc = get_id_by_phone(call->in_phone_hash, &id); 373 385 if (rc != EOK) 374 386 return rc; 375 387 376 388 /* Delete from phone-to-id map. */ 377 389 keys[0] = call->in_phone_hash; 378 390 hash_table_remove(&phone_to_id, keys, 1); 379 391 380 392 /* Mark task as finished. */ 381 393 keys[0] = LOWER32(id); 382 394 keys[1] = UPPER32(id); 383 395 384 396 link_t *link = hash_table_find(&task_hash_table, keys); 385 397 hashed_task_t *ht = … … 387 399 if (ht == NULL) 388 400 return EOK; 389 401 390 402 ht->finished = true; 391 392 return EOK; 393 } 394 395 static int get_id_by_phone(ipcarg_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 403 409 404 return EOK; 410 405 }
Note:
See TracChangeset
for help on using the changeset viewer.