45,7 → 45,6 |
#include <stdlib.h> |
#include <string.h> |
#include <ipc/devmap.h> |
#include <assert.h> |
|
#define NAME "devmap" |
|
95,9 → 94,6 |
LIST_INITIALIZE(drivers_list); |
LIST_INITIALIZE(pending_req); |
|
static bool pending_new_dev = false; |
static FIBRIL_CONDVAR_INITIALIZE(pending_cv); |
|
/* Locking order: |
* drivers_list_mutex |
* devices_list_mutex |
178,8 → 174,10 |
} |
|
/** |
* |
* Unregister device and free it. It's assumed that driver's device list is |
* already locked. |
* |
*/ |
static int devmap_device_unregister_core(devmap_device_t *device) |
{ |
193,8 → 191,10 |
} |
|
/** |
* |
* Read info about new driver and add it into linked list of registered |
* drivers. |
* |
*/ |
static void devmap_driver_register(devmap_driver_t **odriver) |
{ |
349,12 → 349,8 |
static void process_pending_lookup(void) |
{ |
link_t *cur; |
|
|
loop: |
fibril_mutex_lock(&devices_list_mutex); |
while (!pending_new_dev) |
fibril_condvar_wait(&pending_cv, &devices_list_mutex); |
rescan: |
for (cur = pending_req.next; cur != &pending_req; cur = cur->next) { |
pending_req_t *pr = list_get_instance(cur, pending_req_t, link); |
|
368,11 → 364,8 |
list_remove(cur); |
free(pr); |
|
goto rescan; |
goto loop; |
} |
pending_new_dev = false; |
fibril_mutex_unlock(&devices_list_mutex); |
goto loop; |
} |
|
|
452,8 → 445,6 |
list_append(&device->driver_devices, &device->driver->devices); |
|
fibril_mutex_unlock(&device->driver->devices_mutex); |
pending_new_dev = true; |
fibril_condvar_signal(&pending_cv); |
fibril_mutex_unlock(&devices_list_mutex); |
|
ipc_answer_1(iid, EOK, device->handle); |
539,8 → 530,6 |
} |
name[size] = '\0'; |
|
fibril_mutex_lock(&devices_list_mutex); |
|
/* |
* Find device name in linked list of known devices. |
*/ |
554,7 → 543,6 |
/* Blocking lookup, add to pending list */ |
pending_req_t *pr = (pending_req_t *) malloc(sizeof(pending_req_t)); |
if (!pr) { |
fibril_mutex_unlock(&devices_list_mutex); |
ipc_answer_0(iid, ENOMEM); |
free(name); |
return; |
563,16 → 551,13 |
pr->name = name; |
pr->callid = iid; |
list_append(&pr->link, &pending_req); |
fibril_mutex_unlock(&devices_list_mutex); |
return; |
} |
|
ipc_answer_0(iid, ENOENT); |
free(name); |
fibril_mutex_unlock(&devices_list_mutex); |
return; |
} |
fibril_mutex_unlock(&devices_list_mutex); |
|
ipc_answer_1(iid, EOK, dev->handle); |
free(name); |
674,7 → 659,7 |
* |
* |
*/ |
static bool devmap_init(void) |
static bool devmap_init() |
{ |
/* Create NULL device entry */ |
devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t)); |
833,13 → 818,10 |
return -1; |
} |
|
/* Set a handler of incomming connections */ |
/* Set a handler of incomming connections and |
pending operations */ |
async_set_pending(process_pending_lookup); |
async_set_client_connection(devmap_connection); |
|
/* Create a fibril for handling pending device lookups */ |
fid_t fid = fibril_create(process_pending_lookup, NULL); |
assert(fid); |
fibril_add_ready(fid); |
|
/* Register device mapper at naming service */ |
ipcarg_t phonead; |