Changeset 622dea8 in mainline


Ignore:
Timestamp:
2011-01-09T21:14:19Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7ea7db31
Parents:
8b5c8ae
Message:

Protect devman_get_phone() by a mutex.

File:
1 edited

Legend:

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

    r8b5c8ae 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)
     
    6470                            SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
    6571               
     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)
     
    7585                        devman_phone_client = async_connect_me_to(PHONE_NS,
    7686                            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:
Note: See TracChangeset for help on using the changeset viewer.