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