Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/devman.c

    r96b02eb9 r622dea8  
    4242#include <devman.h>
    4343#include <async.h>
     44#include <fibril_synch.h>
    4445#include <errno.h>
    4546#include <malloc.h>
     
    5051static int devman_phone_client = -1;
    5152
     53static FIBRIL_MUTEX_INITIALIZE(devman_phone_mutex);
     54
    5255int devman_get_phone(devman_interface_t iface, unsigned int flags)
    5356{
    5457        switch (iface) {
    5558        case DEVMAN_DRIVER:
    56                 if (devman_phone_driver >= 0)
     59                fibril_mutex_lock(&devman_phone_mutex);
     60                if (devman_phone_driver >= 0) {
     61                        fibril_mutex_unlock(&devman_phone_mutex);
    5762                        return devman_phone_driver;
     63                }
    5864               
    5965                if (flags & IPC_FLAG_BLOCKING)
    60                         devman_phone_driver = ipc_connect_me_to_blocking(PHONE_NS,
     66                        devman_phone_driver = async_connect_me_to_blocking(
     67                            PHONE_NS, SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
     68                else
     69                        devman_phone_driver = async_connect_me_to(PHONE_NS,
    6170                            SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
    62                 else
    63                         devman_phone_driver = ipc_connect_me_to(PHONE_NS,
    64                             SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
    65                
     71               
     72                fibril_mutex_unlock(&devman_phone_mutex);
    6673                return devman_phone_driver;
    6774        case DEVMAN_CLIENT:
    68                 if (devman_phone_client >= 0)
     75                fibril_mutex_lock(&devman_phone_mutex);
     76                if (devman_phone_client >= 0) {
     77                        fibril_mutex_unlock(&devman_phone_mutex);
    6978                        return devman_phone_client;
     79                }
    7080               
    7181                if (flags & IPC_FLAG_BLOCKING)
    72                         devman_phone_client = ipc_connect_me_to_blocking(PHONE_NS,
     82                        devman_phone_client = async_connect_me_to_blocking(
     83                            PHONE_NS, SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
     84                else
     85                        devman_phone_client = async_connect_me_to(PHONE_NS,
    7386                            SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
    74                 else
    75                         devman_phone_client = ipc_connect_me_to(PHONE_NS,
    76                             SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
    77                
     87                        fibril_mutex_unlock(&devman_phone_mutex);
     88               
     89                fibril_mutex_unlock(&devman_phone_mutex);
    7890                return devman_phone_client;
    7991        default:
     
    230242       
    231243        if (flags & IPC_FLAG_BLOCKING) {
    232                 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,
     244                phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,
    233245                    DEVMAN_CONNECT_TO_DEVICE, handle);
    234246        } else {
    235                 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,
     247                phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN,
    236248                    DEVMAN_CONNECT_TO_DEVICE, handle);
    237249        }
     
    245257       
    246258        if (flags & IPC_FLAG_BLOCKING) {
    247                 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,
     259                phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,
    248260                    DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);
    249261        } else {
    250                 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,
     262                phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN,
    251263                    DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);
    252264        }
Note: See TracChangeset for help on using the changeset viewer.