Changeset 1cab2f41 in mainline
- Timestamp:
- 2009-06-26T15:05:36Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- af65b72
- Parents:
- 103bb68
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
r103bb68 r1cab2f41 46 46 #include <string.h> 47 47 #include <ipc/devmap.h> 48 #include <assert.h>49 48 50 49 #define NAME "devmap" … … 85 84 } devmap_device_t; 86 85 87 /** Pending lookup structure. */88 typedef struct {89 link_t link;90 char *name; /**< Device name */91 ipc_callid_t callid; /**< Call ID waiting for the lookup */92 } pending_req_t;93 94 86 LIST_INITIALIZE(devices_list); 95 87 LIST_INITIALIZE(drivers_list); 96 LIST_INITIALIZE(pending_req);97 98 static bool pending_new_dev = false;99 static FIBRIL_CONDVAR_INITIALIZE(pending_cv);100 88 101 89 /* Locking order: … … 107 95 108 96 static FIBRIL_MUTEX_INITIALIZE(devices_list_mutex); 97 static FIBRIL_CONDVAR_INITIALIZE(devices_list_cv); 109 98 static FIBRIL_MUTEX_INITIALIZE(drivers_list_mutex); 110 99 static FIBRIL_MUTEX_INITIALIZE(create_handle_mutex); … … 344 333 return EOK; 345 334 } 346 347 348 /** Process pending lookup requests */349 static void process_pending_lookup(void)350 {351 link_t *cur;352 353 loop:354 fibril_mutex_lock(&devices_list_mutex);355 while (!pending_new_dev)356 fibril_condvar_wait(&pending_cv, &devices_list_mutex);357 rescan:358 for (cur = pending_req.next; cur != &pending_req; cur = cur->next) {359 pending_req_t *pr = list_get_instance(cur, pending_req_t, link);360 361 const devmap_device_t *dev = devmap_device_find_name(pr->name);362 if (!dev)363 continue;364 365 ipc_answer_1(pr->callid, EOK, dev->handle);366 367 free(pr->name);368 list_remove(cur);369 free(pr);370 371 goto rescan;372 }373 pending_new_dev = false;374 fibril_mutex_unlock(&devices_list_mutex);375 goto loop;376 }377 378 335 379 336 /** Register instance of device … … 453 410 454 411 fibril_mutex_unlock(&device->driver->devices_mutex); 455 pending_new_dev = true; 456 fibril_condvar_signal(&pending_cv); 412 fibril_condvar_broadcast(&devices_list_cv); 457 413 fibril_mutex_unlock(&devices_list_mutex); 458 414 … … 541 497 542 498 fibril_mutex_lock(&devices_list_mutex); 543 544 /* 545 * Find device name in linked list of known devices. 546 */ 547 const devmap_device_t *dev = devmap_device_find_name(name); 499 const devmap_device_t *dev; 500 recheck: 501 502 /* 503 * Find device name in the list of known devices. 504 */ 505 dev = devmap_device_find_name(name); 548 506 549 507 /* … … 552 510 if (dev == NULL) { 553 511 if (IPC_GET_ARG1(*icall) & IPC_FLAG_BLOCKING) { 554 /* Blocking lookup, add to pending list */ 555 pending_req_t *pr = (pending_req_t *) malloc(sizeof(pending_req_t)); 556 if (!pr) { 557 fibril_mutex_unlock(&devices_list_mutex); 558 ipc_answer_0(iid, ENOMEM); 559 free(name); 560 return; 561 } 562 563 pr->name = name; 564 pr->callid = iid; 565 list_append(&pr->link, &pending_req); 566 fibril_mutex_unlock(&devices_list_mutex); 567 return; 512 /* Blocking lookup */ 513 fibril_condvar_wait(&devices_list_cv, 514 &devices_list_mutex); 515 goto recheck; 568 516 } 569 517 … … 837 785 async_set_client_connection(devmap_connection); 838 786 839 /* Create a fibril for handling pending device lookups */840 fid_t fid = fibril_create(process_pending_lookup, NULL);841 assert(fid);842 fibril_add_ready(fid);843 844 787 /* Register device mapper at naming service */ 845 788 ipcarg_t phonead;
Note:
See TracChangeset
for help on using the changeset viewer.