Changeset 5d0e461 in mainline
- Timestamp:
- 2009-06-03T18:43:15Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 40313e4
- Parents:
- 8dc12ac
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
r8dc12ac r5d0e461 42 42 #include <errno.h> 43 43 #include <bool.h> 44 #include <futex.h>45 44 #include <stdlib.h> 46 45 #include <string.h> … … 63 62 /** Device driver name */ 64 63 char *name; 65 /** Futex for list of devices owned by this driver */66 atomic_t devices_futex;67 64 } devmap_driver_t; 68 65 … … 95 92 LIST_INITIALIZE(pending_req); 96 93 97 /* Locking order:98 * drivers_list_futex99 * devices_list_futex100 * (devmap_driver_t *)->devices_futex101 * create_handle_futex102 **/103 104 static atomic_t devices_list_futex = FUTEX_INITIALIZER;105 static atomic_t drivers_list_futex = FUTEX_INITIALIZER;106 static atomic_t create_handle_futex = FUTEX_INITIALIZER;107 108 94 static dev_handle_t last_handle = 0; 109 95 … … 111 97 { 112 98 /* TODO: allow reusing old handles after their unregistration 113 * and implement some version of LRU algorithm 114 */ 115 116 /* FIXME: overflow */ 117 futex_down(&create_handle_futex); 99 * and implement some version of LRU algorithm, avoid overflow 100 */ 101 118 102 last_handle++; 119 futex_up(&create_handle_futex);120 103 121 104 return last_handle; … … 132 115 while (item != &devices_list) { 133 116 device = list_get_instance(item, devmap_device_t, devices); 134 if ( 0 == str_cmp(device->name, name))117 if (str_cmp(device->name, name) == 0) 135 118 break; 136 119 item = item->next; … … 151 134 static devmap_device_t *devmap_device_find_handle(dev_handle_t handle) 152 135 { 153 futex_down(&devices_list_futex);154 155 136 link_t *item = (&devices_list)->next; 156 137 devmap_device_t *device = NULL; … … 163 144 } 164 145 165 if (item == &devices_list) { 166 futex_up(&devices_list_futex); 146 if (item == &devices_list) 167 147 return NULL; 168 }169 148 170 149 device = list_get_instance(item, devmap_device_t, devices); 171 172 futex_up(&devices_list_futex);173 150 174 151 return device; … … 250 227 * Send confirmation to sender and get data into buffer. 251 228 */ 252 if ( EOK != ipc_data_write_finalize(callid, driver->name, name_size)) {229 if (ipc_data_write_finalize(callid, driver->name, name_size) != EOK) { 253 230 free(driver->name); 254 231 free(driver); … … 259 236 driver->name[name_size] = 0; 260 237 261 /* Initialize futex for list of devices owned by this driver */262 futex_initialize(&(driver->devices_futex), 1);263 264 238 /* 265 239 * Initialize list of asociated devices … … 268 242 269 243 /* 270 * Create connection to the driver 244 * Create connection to the driver 271 245 */ 272 246 ipc_call_t call; 273 247 callid = async_get_call(&call); 274 248 275 if (IPC_ M_CONNECT_TO_ME != IPC_GET_METHOD(call)) {249 if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { 276 250 ipc_answer_0(callid, ENOTSUP); 277 251 … … 288 262 list_initialize(&(driver->drivers)); 289 263 290 futex_down(&drivers_list_futex);291 292 264 /* TODO: 293 265 * check that no driver with name equal to driver->name is registered … … 298 270 */ 299 271 list_append(&(driver->drivers), &drivers_list); 300 futex_up(&drivers_list_futex);301 272 302 273 ipc_answer_0(iid, EOK); … … 315 286 return EEXISTS; 316 287 317 futex_down(&drivers_list_futex);318 319 288 if (driver->phone != 0) 320 289 ipc_hangup(driver->phone); … … 322 291 /* Remove it from list of drivers */ 323 292 list_remove(&(driver->drivers)); 324 325 /* Unregister all its devices */326 futex_down(&devices_list_futex);327 futex_down(&(driver->devices_futex));328 293 329 294 while (!list_empty(&(driver->devices))) { … … 333 298 } 334 299 335 futex_up(&(driver->devices_futex));336 futex_up(&devices_list_futex);337 futex_up(&drivers_list_futex);338 339 300 /* free name and driver */ 340 301 if (driver->name != NULL) … … 348 309 349 310 /** Process pending lookup requests */ 350 static void process_pending_lookup() 351 { 311 static void process_pending_lookup(void) 312 { 313 async_serialize_start(); 314 352 315 link_t *cur; 353 316 … … 365 328 list_remove(cur); 366 329 free(pr); 330 367 331 goto loop; 368 332 } 333 334 async_serialize_end(); 369 335 } 370 336 … … 420 386 list_initialize(&(device->driver_devices)); 421 387 422 futex_down(&devices_list_futex);423 424 388 /* Check that device with such name is not already registered */ 425 389 if (NULL != devmap_device_find_name(device->name)) { 426 390 printf(NAME ": Device '%s' already registered\n", device->name); 427 futex_up(&devices_list_futex);428 391 free(device->name); 429 392 free(device); … … 440 403 list_append(&device->devices, &devices_list); 441 404 442 /* Insert device into list of devices that belog to one driver */443 futex_down(&device->driver->devices_futex);444 445 405 list_append(&device->driver_devices, &device->driver->devices); 446 406 447 futex_up(&device->driver->devices_futex);448 futex_up(&devices_list_futex);449 450 407 ipc_answer_1(iid, EOK, device->handle); 451 452 process_pending_lookup();453 408 } 454 409 … … 601 556 static void devmap_get_count(ipc_callid_t iid, ipc_call_t *icall) 602 557 { 603 futex_down(&devices_list_futex);604 558 ipc_answer_1(iid, EOK, list_count(&devices_list)); 605 futex_up(&devices_list_futex);606 559 } 607 560 608 561 static void devmap_get_devices(ipc_callid_t iid, ipc_call_t *icall) 609 562 { 610 futex_down(&devices_list_futex);611 612 563 ipc_callid_t callid; 613 564 size_t size; … … 624 575 } 625 576 626 count_t count = size / sizeof(dev_desc_t);577 size_t count = size / sizeof(dev_desc_t); 627 578 dev_desc_t *desc = (dev_desc_t *) malloc(size); 628 579 if (desc == NULL) { … … 632 583 } 633 584 634 count_t pos = 0;585 size_t pos = 0; 635 586 link_t *item = devices_list.next; 636 587 … … 653 604 free(desc); 654 605 655 futex_up(&devices_list_futex);656 657 606 ipc_answer_1(iid, EOK, pos); 658 607 } … … 678 627 list_initialize(&(device->driver_devices)); 679 628 680 futex_down(&devices_list_futex);681 682 629 /* Get unique device handle */ 683 630 device->handle = devmap_create_handle(); … … 687 634 list_append(&device->devices, &devices_list); 688 635 689 futex_up(&devices_list_futex);690 691 636 return true; 692 637 } … … 700 645 ipc_answer_0(iid, EOK); 701 646 702 devmap_driver_t *driver = NULL; 647 devmap_driver_t *driver = NULL; 703 648 devmap_driver_register(&driver); 704 649 … … 711 656 ipc_callid_t callid = async_get_call(&call); 712 657 658 async_serialize_start(); 659 713 660 switch (IPC_GET_METHOD(call)) { 714 661 case IPC_M_PHONE_HUNGUP: 715 662 cont = false; 716 /* Exit thread */663 async_serialize_end(); 717 664 continue; 718 665 case DEVMAP_DRIVER_UNREGISTER: … … 740 687 ipc_answer_0(callid, ENOENT); 741 688 } 689 690 async_serialize_end(); 742 691 } 743 692 … … 746 695 * Unregister the device driver and all its devices. 747 696 */ 697 698 async_serialize_start(); 699 748 700 devmap_driver_unregister(driver); 749 701 driver = NULL; 702 703 async_serialize_end(); 750 704 } 751 705 } … … 764 718 ipc_callid_t callid = async_get_call(&call); 765 719 720 async_serialize_start(); 721 766 722 switch (IPC_GET_METHOD(call)) { 767 723 case IPC_M_PHONE_HUNGUP: 768 724 cont = false; 769 /* Exit thread */725 async_serialize_end(); 770 726 continue; 771 727 case DEVMAP_DEVICE_GET_HANDLE: … … 785 741 ipc_answer_0(callid, ENOENT); 786 742 } 743 744 async_serialize_end(); 787 745 } 788 746 } … … 807 765 default: 808 766 /* No such interface */ 809 ipc_answer_0(iid, ENOENT); 767 ipc_answer_0(iid, ENOENT); 810 768 } 811 769 } … … 823 781 } 824 782 825 /* Set a handler of incomming connections */ 783 /* Set a handler of incomming connections and 784 pending operations */ 785 async_set_pending(process_pending_lookup); 826 786 async_set_client_connection(devmap_connection); 827 787
Note:
See TracChangeset
for help on using the changeset viewer.