legacy_drivers: convert to BOpenHashTable.
This commit is contained in:
@@ -226,7 +226,6 @@ static status_t unload_driver(legacy_driver *driver);
|
|||||||
static status_t load_driver(legacy_driver *driver);
|
static status_t load_driver(legacy_driver *driver);
|
||||||
|
|
||||||
|
|
||||||
static hash_table* sDriverHash;
|
|
||||||
static DriverWatcher sDriverWatcher;
|
static DriverWatcher sDriverWatcher;
|
||||||
static int32 sDriverEventsPending;
|
static int32 sDriverEventsPending;
|
||||||
static DriverEventList sDriverEvents;
|
static DriverEventList sDriverEvents;
|
||||||
@@ -241,27 +240,35 @@ static bool sWatching;
|
|||||||
// #pragma mark - driver private
|
// #pragma mark - driver private
|
||||||
|
|
||||||
|
|
||||||
static uint32
|
struct DriverHash {
|
||||||
driver_entry_hash(void *_driver, const void *_key, uint32 range)
|
typedef const char* KeyType;
|
||||||
{
|
typedef legacy_driver ValueType;
|
||||||
legacy_driver *driver = (legacy_driver *)_driver;
|
|
||||||
const char *key = (const char *)_key;
|
|
||||||
|
|
||||||
if (driver != NULL)
|
size_t HashKey(KeyType key) const
|
||||||
return hash_hash_string(driver->name) % range;
|
{
|
||||||
|
return hash_hash_string(key);
|
||||||
|
}
|
||||||
|
|
||||||
return hash_hash_string(key) % range;
|
size_t Hash(ValueType* driver) const
|
||||||
}
|
{
|
||||||
|
return HashKey(driver->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Compare(KeyType key, ValueType* driver) const
|
||||||
|
{
|
||||||
|
return strcmp(driver->name, key) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueType*& GetLink(ValueType* value) const
|
||||||
|
{
|
||||||
|
return value->next;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef BOpenHashTable<DriverHash> DriverTable;
|
||||||
|
|
||||||
|
|
||||||
static int
|
static DriverTable* sDriverHash;
|
||||||
driver_entry_compare(void *_driver, const void *_key)
|
|
||||||
{
|
|
||||||
legacy_driver *driver = (legacy_driver *)_driver;
|
|
||||||
const char *key = (const char *)_key;
|
|
||||||
|
|
||||||
return strcmp(driver->name, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*! Collects all published devices of a driver, compares them to what the
|
/*! Collects all published devices of a driver, compares them to what the
|
||||||
@@ -543,18 +550,14 @@ get_leaf(const char *path)
|
|||||||
static legacy_driver *
|
static legacy_driver *
|
||||||
find_driver(dev_t device, ino_t node)
|
find_driver(dev_t device, ino_t node)
|
||||||
{
|
{
|
||||||
hash_iterator iterator;
|
DriverTable::Iterator iterator(sDriverHash);
|
||||||
hash_open(sDriverHash, &iterator);
|
while (iterator.HasNext()) {
|
||||||
legacy_driver *driver;
|
legacy_driver *driver = iterator.Next();
|
||||||
while (true) {
|
if (driver->device == device && driver->node == node)
|
||||||
driver = (legacy_driver *)hash_next(sDriverHash, &iterator);
|
return driver;
|
||||||
if (driver == NULL
|
|
||||||
|| (driver->device == device && driver->node == node))
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hash_close(sDriverHash, &iterator, false);
|
return NULL;
|
||||||
return driver;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -579,8 +582,7 @@ add_driver(const char *path, image_id image)
|
|||||||
|
|
||||||
RecursiveLocker _(sLock);
|
RecursiveLocker _(sLock);
|
||||||
|
|
||||||
legacy_driver *driver = (legacy_driver *)hash_lookup(sDriverHash,
|
legacy_driver *driver = sDriverHash->Lookup(get_leaf(path));
|
||||||
get_leaf(path));
|
|
||||||
if (driver != NULL) {
|
if (driver != NULL) {
|
||||||
// we know this driver
|
// we know this driver
|
||||||
if (strcmp(driver->path, path) != 0) {
|
if (strcmp(driver->path, path) != 0) {
|
||||||
@@ -638,7 +640,7 @@ add_driver(const char *path, image_id image)
|
|||||||
driver->uninit_hardware = NULL;
|
driver->uninit_hardware = NULL;
|
||||||
new(&driver->devices) DeviceList;
|
new(&driver->devices) DeviceList;
|
||||||
|
|
||||||
hash_insert(sDriverHash, driver);
|
sDriverHash->Insert(driver);
|
||||||
if (stat.st_dev > 0)
|
if (stat.st_dev > 0)
|
||||||
change_driver_watcher(stat.st_dev, stat.st_ino, true);
|
change_driver_watcher(stat.st_dev, stat.st_ino, true);
|
||||||
|
|
||||||
@@ -715,7 +717,7 @@ handle_driver_events(void */*_fs*/, int /*iteration*/)
|
|||||||
RecursiveLocker locker(sLock);
|
RecursiveLocker locker(sLock);
|
||||||
TRACE((" add driver %p\n", event->path));
|
TRACE((" add driver %p\n", event->path));
|
||||||
|
|
||||||
legacy_driver* driver = (legacy_driver*)hash_lookup(sDriverHash,
|
legacy_driver* driver = sDriverHash->Lookup(
|
||||||
get_leaf(event->path));
|
get_leaf(event->path));
|
||||||
if (driver == NULL)
|
if (driver == NULL)
|
||||||
legacy_driver_add(event->path);
|
legacy_driver_add(event->path);
|
||||||
@@ -730,7 +732,7 @@ handle_driver_events(void */*_fs*/, int /*iteration*/)
|
|||||||
RecursiveLocker locker(sLock);
|
RecursiveLocker locker(sLock);
|
||||||
TRACE((" remove driver %p\n", event->path));
|
TRACE((" remove driver %p\n", event->path));
|
||||||
|
|
||||||
legacy_driver* driver = (legacy_driver*)hash_lookup(sDriverHash,
|
legacy_driver* driver = sDriverHash->Lookup(
|
||||||
get_leaf(event->path));
|
get_leaf(event->path));
|
||||||
if (driver != NULL
|
if (driver != NULL
|
||||||
&& get_priority(event->path) >= driver->priority)
|
&& get_priority(event->path) >= driver->priority)
|
||||||
@@ -760,13 +762,10 @@ handle_driver_events(void */*_fs*/, int /*iteration*/)
|
|||||||
|
|
||||||
RecursiveLocker locker(sLock);
|
RecursiveLocker locker(sLock);
|
||||||
|
|
||||||
hash_iterator iterator;
|
DriverTable::Iterator iterator(sDriverHash);
|
||||||
hash_open(sDriverHash, &iterator);
|
while (iterator.HasNext()) {
|
||||||
legacy_driver *driver;
|
legacy_driver *driver = iterator.Next();
|
||||||
while (true) {
|
|
||||||
driver = (legacy_driver *)hash_next(sDriverHash, &iterator);
|
|
||||||
if (driver == NULL)
|
|
||||||
break;
|
|
||||||
if (!driver->binary_updated || driver->devices_used != 0)
|
if (!driver->binary_updated || driver->devices_used != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -774,7 +773,6 @@ handle_driver_events(void */*_fs*/, int /*iteration*/)
|
|||||||
reload_driver(driver);
|
reload_driver(driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
hash_close(sDriverHash, &iterator, false);
|
|
||||||
locker.Unlock();
|
locker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -876,13 +874,9 @@ dump_driver(int argc, char** argv)
|
|||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
// print list of all drivers
|
// print list of all drivers
|
||||||
kprintf("address image used publ. pri name\n");
|
kprintf("address image used publ. pri name\n");
|
||||||
hash_iterator iterator;
|
DriverTable::Iterator iterator(sDriverHash);
|
||||||
hash_open(sDriverHash, &iterator);
|
while (iterator.HasNext()) {
|
||||||
while (true) {
|
legacy_driver* driver = iterator.Next();
|
||||||
legacy_driver* driver = (legacy_driver*)hash_next(sDriverHash,
|
|
||||||
&iterator);
|
|
||||||
if (driver == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
kprintf("%p %5" B_PRId32 " %3" B_PRIu32 " %5" B_PRId32 " %c "
|
kprintf("%p %5" B_PRId32 " %3" B_PRIu32 " %5" B_PRId32 " %c "
|
||||||
"%3" B_PRId32 " %s\n", driver,
|
"%3" B_PRId32 " %s\n", driver,
|
||||||
@@ -892,7 +886,6 @@ dump_driver(int argc, char** argv)
|
|||||||
driver->name);
|
driver->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
hash_close(sDriverHash, &iterator, false);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -901,7 +894,7 @@ dump_driver(int argc, char** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
legacy_driver* driver = (legacy_driver*)hash_lookup(sDriverHash, argv[1]);
|
legacy_driver* driver = sDriverHash->Lookup(argv[1]);
|
||||||
if (driver == NULL) {
|
if (driver == NULL) {
|
||||||
kprintf("Driver named \"%s\" not found.\n", argv[1]);
|
kprintf("Driver named \"%s\" not found.\n", argv[1]);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1458,8 +1451,7 @@ legacy_driver_rescan(const char* driverName)
|
|||||||
{
|
{
|
||||||
RecursiveLocker locker(sLock);
|
RecursiveLocker locker(sLock);
|
||||||
|
|
||||||
legacy_driver* driver = (legacy_driver*)hash_lookup(sDriverHash,
|
legacy_driver* driver = sDriverHash->Lookup(driverName);
|
||||||
driverName);
|
|
||||||
if (driver == NULL)
|
if (driver == NULL)
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
@@ -1518,11 +1510,8 @@ legacy_driver_probe(const char* subPath)
|
|||||||
extern "C" status_t
|
extern "C" status_t
|
||||||
legacy_driver_init(void)
|
legacy_driver_init(void)
|
||||||
{
|
{
|
||||||
legacy_driver dummyDriver;
|
sDriverHash = new DriverTable();
|
||||||
sDriverHash = hash_init(DRIVER_HASH_SIZE,
|
if (sDriverHash == NULL || sDriverHash->Init(DRIVER_HASH_SIZE) != B_OK)
|
||||||
offset_of_member(dummyDriver, next), &driver_entry_compare,
|
|
||||||
&driver_entry_hash);
|
|
||||||
if (sDriverHash == NULL)
|
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
recursive_lock_init(&sLock, "legacy driver");
|
recursive_lock_init(&sLock, "legacy driver");
|
||||||
|
|||||||
Reference in New Issue
Block a user