Changeset 5d0e461 in mainline


Ignore:
Timestamp:
2009-06-03T18:43:15Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
40313e4
Parents:
8dc12ac
Message:

remove futex (devmap is not multithreaded), use fibril serialization instead

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devmap/devmap.c

    r8dc12ac r5d0e461  
    4242#include <errno.h>
    4343#include <bool.h>
    44 #include <futex.h>
    4544#include <stdlib.h>
    4645#include <string.h>
     
    6362        /** Device driver name */
    6463        char *name;
    65         /** Futex for list of devices owned by this driver */
    66         atomic_t devices_futex;
    6764} devmap_driver_t;
    6865
     
    9592LIST_INITIALIZE(pending_req);
    9693
    97 /* Locking order:
    98  *  drivers_list_futex
    99  *  devices_list_futex
    100  *  (devmap_driver_t *)->devices_futex
    101  *  create_handle_futex
    102  **/
    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 
    10894static dev_handle_t last_handle = 0;
    10995
     
    11197{
    11298        /* 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       
    118102        last_handle++;
    119         futex_up(&create_handle_futex);
    120103       
    121104        return last_handle;
     
    132115        while (item != &devices_list) {
    133116                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)
    135118                        break;
    136119                item = item->next;
     
    151134static devmap_device_t *devmap_device_find_handle(dev_handle_t handle)
    152135{
    153         futex_down(&devices_list_futex);
    154        
    155136        link_t *item = (&devices_list)->next;
    156137        devmap_device_t *device = NULL;
     
    163144        }
    164145       
    165         if (item == &devices_list) {
    166                 futex_up(&devices_list_futex);
     146        if (item == &devices_list)
    167147                return NULL;
    168         }
    169148       
    170149        device = list_get_instance(item, devmap_device_t, devices);
    171        
    172         futex_up(&devices_list_futex);
    173150       
    174151        return device;
     
    250227         * Send confirmation to sender and get data into buffer.
    251228         */
    252         if (EOK != ipc_data_write_finalize(callid, driver->name, name_size)) {
     229        if (ipc_data_write_finalize(callid, driver->name, name_size) != EOK) {
    253230                free(driver->name);
    254231                free(driver);
     
    259236        driver->name[name_size] = 0;
    260237       
    261         /* Initialize futex for list of devices owned by this driver */
    262         futex_initialize(&(driver->devices_futex), 1);
    263        
    264238        /*
    265239         * Initialize list of asociated devices
     
    268242       
    269243        /*
    270          * Create connection to the driver 
     244         * Create connection to the driver
    271245         */
    272246        ipc_call_t call;
    273247        callid = async_get_call(&call);
    274248       
    275         if (IPC_M_CONNECT_TO_ME != IPC_GET_METHOD(call)) {
     249        if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
    276250                ipc_answer_0(callid, ENOTSUP);
    277251               
     
    288262        list_initialize(&(driver->drivers));
    289263       
    290         futex_down(&drivers_list_futex);
    291        
    292264        /* TODO:
    293265         * check that no driver with name equal to driver->name is registered
     
    298270         */
    299271        list_append(&(driver->drivers), &drivers_list);
    300         futex_up(&drivers_list_futex);
    301272       
    302273        ipc_answer_0(iid, EOK);
     
    315286                return EEXISTS;
    316287       
    317         futex_down(&drivers_list_futex);
    318        
    319288        if (driver->phone != 0)
    320289                ipc_hangup(driver->phone);
     
    322291        /* Remove it from list of drivers */
    323292        list_remove(&(driver->drivers));
    324        
    325         /* Unregister all its devices */
    326         futex_down(&devices_list_futex);
    327         futex_down(&(driver->devices_futex));
    328293       
    329294        while (!list_empty(&(driver->devices))) {
     
    333298        }
    334299       
    335         futex_up(&(driver->devices_futex));
    336         futex_up(&devices_list_futex);
    337         futex_up(&drivers_list_futex);
    338        
    339300        /* free name and driver */
    340301        if (driver->name != NULL)
     
    348309
    349310/** Process pending lookup requests */
    350 static void process_pending_lookup()
    351 {
     311static void process_pending_lookup(void)
     312{
     313        async_serialize_start();
     314       
    352315        link_t *cur;
    353316       
     
    365328                list_remove(cur);
    366329                free(pr);
     330               
    367331                goto loop;
    368332        }
     333       
     334        async_serialize_end();
    369335}
    370336
     
    420386        list_initialize(&(device->driver_devices));
    421387       
    422         futex_down(&devices_list_futex);
    423        
    424388        /* Check that device with such name is not already registered */
    425389        if (NULL != devmap_device_find_name(device->name)) {
    426390                printf(NAME ": Device '%s' already registered\n", device->name);
    427                 futex_up(&devices_list_futex); 
    428391                free(device->name);
    429392                free(device);
     
    440403        list_append(&device->devices, &devices_list);
    441404       
    442         /* Insert device into list of devices that belog to one driver */
    443         futex_down(&device->driver->devices_futex);     
    444        
    445405        list_append(&device->driver_devices, &device->driver->devices);
    446406       
    447         futex_up(&device->driver->devices_futex);
    448         futex_up(&devices_list_futex);
    449        
    450407        ipc_answer_1(iid, EOK, device->handle);
    451        
    452         process_pending_lookup();
    453408}
    454409
     
    601556static void devmap_get_count(ipc_callid_t iid, ipc_call_t *icall)
    602557{
    603         futex_down(&devices_list_futex);
    604558        ipc_answer_1(iid, EOK, list_count(&devices_list));
    605         futex_up(&devices_list_futex);
    606559}
    607560
    608561static void devmap_get_devices(ipc_callid_t iid, ipc_call_t *icall)
    609562{
    610         futex_down(&devices_list_futex);
    611        
    612563        ipc_callid_t callid;
    613564        size_t size;
     
    624575        }
    625576       
    626         count_t count = size / sizeof(dev_desc_t);
     577        size_t count = size / sizeof(dev_desc_t);
    627578        dev_desc_t *desc = (dev_desc_t *) malloc(size);
    628579        if (desc == NULL) {
     
    632583        }
    633584       
    634         count_t pos = 0;
     585        size_t pos = 0;
    635586        link_t *item = devices_list.next;
    636587       
     
    653604        free(desc);
    654605       
    655         futex_up(&devices_list_futex);
    656        
    657606        ipc_answer_1(iid, EOK, pos);
    658607}
     
    678627        list_initialize(&(device->driver_devices));
    679628       
    680         futex_down(&devices_list_futex);
    681        
    682629        /* Get unique device handle */
    683630        device->handle = devmap_create_handle();
     
    687634        list_append(&device->devices, &devices_list);
    688635       
    689         futex_up(&devices_list_futex);
    690        
    691636        return true;
    692637}
     
    700645        ipc_answer_0(iid, EOK);
    701646       
    702         devmap_driver_t *driver = NULL; 
     647        devmap_driver_t *driver = NULL;
    703648        devmap_driver_register(&driver);
    704649       
     
    711656                ipc_callid_t callid = async_get_call(&call);
    712657               
     658                async_serialize_start();
     659               
    713660                switch (IPC_GET_METHOD(call)) {
    714661                case IPC_M_PHONE_HUNGUP:
    715662                        cont = false;
    716                         /* Exit thread */
     663                        async_serialize_end();
    717664                        continue;
    718665                case DEVMAP_DRIVER_UNREGISTER:
     
    740687                                ipc_answer_0(callid, ENOENT);
    741688                }
     689               
     690                async_serialize_end();
    742691        }
    743692       
     
    746695                 * Unregister the device driver and all its devices.
    747696                 */
     697               
     698                async_serialize_start();
     699               
    748700                devmap_driver_unregister(driver);
    749701                driver = NULL;
     702               
     703                async_serialize_end();
    750704        }
    751705}
     
    764718                ipc_callid_t callid = async_get_call(&call);
    765719               
     720                async_serialize_start();
     721               
    766722                switch (IPC_GET_METHOD(call)) {
    767723                case IPC_M_PHONE_HUNGUP:
    768724                        cont = false;
    769                         /* Exit thread */
     725                        async_serialize_end();
    770726                        continue;
    771727                case DEVMAP_DEVICE_GET_HANDLE:
     
    785741                                ipc_answer_0(callid, ENOENT);
    786742                }
     743               
     744                async_serialize_end();
    787745        }
    788746}
     
    807765        default:
    808766                /* No such interface */
    809                 ipc_answer_0(iid, ENOENT); 
     767                ipc_answer_0(iid, ENOENT);
    810768        }
    811769}
     
    823781        }
    824782       
    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);
    826786        async_set_client_connection(devmap_connection);
    827787       
Note: See TracChangeset for help on using the changeset viewer.