[haiku-commits] haiku: hrev48666 - in src: system/kernel system/kernel/fs system/kernel/device_manager add-ons/kernel/file_systems/ext2

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 12 Jan 2015 18:23:38 +0100 (CET)

hrev48666 adds 5 changesets to branch 'master'
old head: c921f4a7a197a74cb8614644ff664d9a5a4d8adc
new head: 63fdcb8e7e09f975bd53e7fc18bc9ff3cfe1294c
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=63fdcb8+%5Ec921f4a

----------------------------------------------------------------------------

887be0a: kernel/module: fully convert to BOpenHashTable

79b1261: legacy_drivers: convert to BOpenHashTable.

6235b49: More useless inclusions of khash.h

f9defd4: VFS: migrate to BOpenHashTable.

63fdcb8: ext2: migrate to BOpenHashTable.

                                 [ Adrien Destugues <pulkomandy@xxxxxxxxx> ]

----------------------------------------------------------------------------

18 files changed, 277 insertions(+), 309 deletions(-)
headers/private/kernel/Notifications.h           |   2 +-
.../file_systems/ext2/HashRevokeManager.cpp      |  39 ++--
.../kernel/file_systems/ext2/HashRevokeManager.h |  35 +++-
.../file_systems/packagefs/indices/Index.h       |   1 -
.../kernel/file_systems/packagefs/nodes/Node.h   |   1 -
.../file_systems/packagefs/package/Package.h     |   2 +-
.../packagefs/resolvables/DependencyFamily.h     |   1 -
.../packagefs/resolvables/ResolvableFamily.h     |   1 -
.../file_systems/packagefs/util/StringPool.h     |   2 +-
.../kernel/network/protocols/tcp/TCPEndpoint.cpp |   1 -
src/add-ons/kernel/network/protocols/tcp/tcp.h   |   2 -
.../network/protocols/unix/UnixAddress.cpp       |   2 +-
.../kernel/device_manager/legacy_drivers.cpp     | 101 +++++-----
src/system/kernel/fs/EntryCache.h                |   2 +-
src/system/kernel/fs/fifo.cpp                    |   4 -
src/system/kernel/fs/node_monitor.cpp            |   1 -
src/system/kernel/fs/vfs.cpp                     | 197 +++++++++----------
src/system/kernel/module.cpp                     | 192 ++++++++----------

############################################################################

Commit:      887be0ac6a35dc308ba2731c1a176cb28338d20d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=887be0a
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Mon Jan 12 13:57:03 2015 UTC

kernel/module: fully convert to BOpenHashTable

----------------------------------------------------------------------------

diff --git a/src/system/kernel/module.cpp b/src/system/kernel/module.cpp
index d5cabc9..8808640 100644
--- a/src/system/kernel/module.cpp
+++ b/src/system/kernel/module.cpp
@@ -314,71 +314,64 @@ static bool sDisableUserAddOns = false;
 */
 static recursive_lock sModulesLock;
 
-/* We store the loaded modules by directory path, and all known modules
- * by module name in a hash table for quick access
- */
-static hash_table* sModuleImagesHash;
-static hash_table* sModulesHash;
 
+struct ModuleHash {
+       typedef const char* KeyType;
+       typedef module ValueType;
 
-/*!    Calculates hash for a module using its name */
-static uint32
-module_hash(void* _module, const void* _key, uint32 range)
-{
-       module* module = (struct module*)_module;
-       const char* name = (const char*)_key;
-
-       if (module != NULL)
-               return hash_hash_string(module->name) % range;
+       size_t Hash(ValueType* module) const
+               { return HashKey(module->name); }
+       ValueType*& GetLink(ValueType* entry) const
+               { return entry->next; }
 
-       if (name != NULL)
-               return hash_hash_string(name) % range;
+       size_t HashKey(KeyType key) const
+       {
+               return hash_hash_string(key);
+       }
 
-       return 0;
-}
+       bool Compare(KeyType key, ValueType* module) const
+       {
+               if (key == NULL)
+                       return false;
+               return strcmp(module->name, key) == 0;
+       }
+};
 
+typedef BOpenHashTable<ModuleHash> ModuleTable;
 
-/*!    Compares a module to a given name */
-static int
-module_compare(void* _module, const void* _key)
-{
-       module* module = (struct module*)_module;
-       const char* name = (const char*)_key;
-       if (name == NULL)
-               return -1;
 
-       return strcmp(module->name, name);
-}
+struct ImageHash {
+       typedef const char* KeyType;
+       typedef module_image ValueType;
 
+       size_t Hash(ValueType* image) const
+               { return HashKey(image->path); }
+       ValueType*& GetLink(ValueType* entry) const
+               { return entry->next; }
 
-/*!    Calculates the hash of a module image using its path */
-static uint32
-module_image_hash(void* _module, const void* _key, uint32 range)
-{
-       module_image* image = (module_image*)_module;
-       const char* path = (const char*)_key;
+       size_t HashKey(KeyType key) const
+       {
+               return hash_hash_string(key);
+       }
 
-       if (image != NULL)
-               return hash_hash_string(image->path) % range;
+       bool Compare(KeyType key, ValueType* image) const
+       {
+               if (key == NULL)
+                       return false;
+               return strcmp(image->path, key) == 0;
+       }
+};
 
-       if (path != NULL)
-               return hash_hash_string(path) % range;
+typedef BOpenHashTable<ImageHash> ImageTable;
 
-       return 0;
-}
 
+/* We store the loaded modules by directory path, and all known modules
+ * by module name in a hash table for quick access
+ */
+static ImageTable* sModuleImagesHash;
+static ModuleTable* sModulesHash;
 
-/*!    Compares a module image to a path */
-static int
-module_image_compare(void* _module, const void* _key)
-{
-       module_image* image = (module_image*)_module;
-       const char* path = (const char*)_key;
-       if (path == NULL)
-               return -1;
 
-       return strcmp(image->path, path);
-}
 
 
 /*!    Try to load the module image at the specified \a path.
@@ -432,7 +425,7 @@ load_module_image(const char* path, module_image** 
_moduleImage)
        moduleImage->image = image;
        moduleImage->ref_count = 0;
 
-       hash_insert(sModuleImagesHash, moduleImage);
+       sModuleImagesHash->Insert(moduleImage);
 
        TRACE(("load_module_image(\"%s\"): image loaded: %p\n", path, 
moduleImage));
 
@@ -458,13 +451,13 @@ unload_module_image(module_image* moduleImage, bool 
remove)
        ASSERT_LOCKED_RECURSIVE(&sModulesLock);
 
        if (moduleImage->ref_count != 0) {
-               FATAL(("Can't unload %s due to ref_cnt = %" B_PRId32 "\n", 
moduleImage->path,
-                       moduleImage->ref_count));
+               FATAL(("Can't unload %s due to ref_cnt = %" B_PRId32 "\n",
+                       moduleImage->path, moduleImage->ref_count));
                return B_ERROR;
        }
 
        if (remove)
-               hash_remove(sModuleImagesHash, moduleImage);
+               sModuleImagesHash->Remove(moduleImage);
 
        unload_kernel_add_on(moduleImage->image);
        free(moduleImage->path);
@@ -499,7 +492,7 @@ get_module_image(const char* path, module_image** _image)
 
        RecursiveLocker _(sModulesLock);
 
-       image = (module_image*)hash_lookup(sModuleImagesHash, path);
+       image = sModuleImagesHash->Lookup(path);
        if (image == NULL) {
                status_t status = load_module_image(path, &image);
                if (status < B_OK)
@@ -527,7 +520,7 @@ create_module(module_info* info, int offset, module** 
_module)
        if (!info->name)
                return B_BAD_VALUE;
 
-       module = (struct module*)hash_lookup(sModulesHash, info->name);
+       module = sModulesHash->Lookup(info->name);
        if (module) {
                FATAL(("Duplicate module name (%s) detected... ignoring new 
one\n",
                        info->name));
@@ -554,7 +547,7 @@ create_module(module_info* info, int offset, module** 
_module)
        module->flags = info->flags;
 
        recursive_lock_lock(&sModulesLock);
-       hash_insert(sModulesHash, module);
+       sModulesHash->Insert(module);
        recursive_lock_unlock(&sModulesLock);
 
        if (_module)
@@ -591,8 +584,7 @@ check_module_image(const char* path, const char* 
searchedName,
                // try to create a module for every module_info, check if the
                // name matches if it was a new entry
                bool freshModule = false;
-               struct module* module = (struct 
module*)hash_lookup(sModulesHash,
-                       (*info)->name);
+               struct module* module = sModulesHash->Lookup((*info)->name);
                if (module != NULL) {
                        // Module does already exist
                        if (module->module_image == NULL && module->ref_count 
== 0) {
@@ -660,7 +652,7 @@ search_module(const char* name, module_image** _moduleImage)
        if (status != B_OK)
                return NULL;
 
-       return (module*)hash_lookup(sModulesHash, name);
+       return sModulesHash->Lookup(name);
 }
 
 
@@ -906,12 +898,11 @@ iterator_get_next_module(module_iterator* iterator, char* 
buffer,
 
        if (iterator->loaded_modules) {
                recursive_lock_lock(&sModulesLock);
-               hash_iterator hashIterator;
-               hash_open(sModulesHash, &hashIterator);
+               ModuleTable::Iterator hashIterator(sModulesHash);
+
+               for (int32 i = 0; hashIterator.HasNext(); i++) {
+                       struct module* module = hashIterator.Next();
 
-               struct module* module = (struct module*)hash_next(sModulesHash,
-                       &hashIterator);
-               for (int32 i = 0; module != NULL; i++) {
                        if (i >= iterator->module_offset) {
                                if (!strncmp(module->name, iterator->prefix,
                                                iterator->prefix_length)
@@ -919,15 +910,12 @@ iterator_get_next_module(module_iterator* iterator, char* 
buffer,
                                        *_bufferSize = strlcpy(buffer, 
module->name, *_bufferSize);
                                        iterator->module_offset = i + 1;
 
-                                       hash_close(sModulesHash, &hashIterator, 
false);
                                        recursive_lock_unlock(&sModulesLock);
                                        return B_OK;
                                }
                        }
-                       module = (struct module*)hash_next(sModulesHash, 
&hashIterator);
                }
 
-               hash_close(sModulesHash, &hashIterator, false);
                recursive_lock_unlock(&sModulesLock);
 
                // prevent from falling into modules hash iteration again
@@ -1139,7 +1127,7 @@ register_preloaded_module_image(struct preloaded_image* 
image)
        moduleImage->image = image->id;
        moduleImage->ref_count = 0;
 
-       hash_insert(sModuleImagesHash, moduleImage);
+       sModuleImagesHash->Insert(moduleImage);
 
        for (info = moduleImage->info; *info; info++) {
                struct module* module = NULL;
@@ -1164,15 +1152,13 @@ error:
 static int
 dump_modules(int argc, char** argv)
 {
-       hash_iterator iterator;
        struct module_image* image;
-       struct module* module;
 
-       hash_rewind(sModulesHash, &iterator);
+       ModuleTable::Iterator iterator(sModulesHash);
        kprintf("-- known modules:\n");
 
-       while ((module = (struct module*)hash_next(sModulesHash, &iterator))
-                       != NULL) {
+       while (iterator.HasNext()) {
+               struct module* module = iterator.Next();
                kprintf("%p: \"%s\", \"%s\" (%" B_PRId32 "), refcount = %" 
B_PRId32 ", "
                        "state = %d, mimage = %p\n", module, module->name,
                        module->module_image ? module->module_image->path : "",
@@ -1180,11 +1166,11 @@ dump_modules(int argc, char** argv)
                        module->module_image);
        }
 
-       hash_rewind(sModuleImagesHash, &iterator);
+       ImageTable::Iterator imageIterator(sModuleImagesHash);
        kprintf("\n-- loaded module images:\n");
 
-       while ((image = (struct module_image*)hash_next(sModuleImagesHash,
-                               &iterator)) != NULL) {
+       while (imageIterator.HasNext()) {
+               image = imageIterator.Next();
                kprintf("%p: \"%s\" (image_id = %" B_PRId32 "), info = %p, 
refcount = "
                        "%" B_PRId32 "\n", image, image->path, image->image, 
image->info,
                        image->ref_count);
@@ -1703,7 +1689,7 @@ ModuleNotificationService::Notify(int32 opcode, dev_t 
device, ino_t directory,
 
 
 /*static*/ void
-ModuleNotificationService::HandleNotifications(void */*data*/,
+ModuleNotificationService::HandleNotifications(void * /*data*/,
        int /*iteration*/)
 {
        sModuleNotificationService._HandleNotifications();
@@ -1722,7 +1708,7 @@ unload_module(const char* path)
        struct module_image* moduleImage;
 
        recursive_lock_lock(&sModulesLock);
-       moduleImage = (module_image*)hash_lookup(sModuleImagesHash, path);
+       moduleImage = sModuleImagesHash->Lookup(path);
        recursive_lock_unlock(&sModulesLock);
 
        if (moduleImage == NULL)
@@ -1788,13 +1774,14 @@ module_init(kernel_args* args)
 
        recursive_lock_init(&sModulesLock, "modules rlock");
 
-       sModulesHash = hash_init(MODULE_HASH_SIZE, 0, module_compare, 
module_hash);
-       if (sModulesHash == NULL)
+       sModulesHash = new(std::nothrow) ModuleTable();
+       if (sModulesHash == NULL
+                       || sModulesHash->Init(MODULE_HASH_SIZE) != B_OK)
                return B_NO_MEMORY;
 
-       sModuleImagesHash = hash_init(MODULE_HASH_SIZE, 0, module_image_compare,
-               module_image_hash);
-       if (sModuleImagesHash == NULL)
+       sModuleImagesHash = new(std::nothrow) ImageTable();
+       if (sModuleImagesHash == NULL
+                       || sModuleImagesHash->Init(MODULE_HASH_SIZE) != B_OK)
                return B_NO_MEMORY;
 
        // register built-in modules
@@ -1847,11 +1834,10 @@ module_init_post_boot_device(bool 
bootingFromBootLoaderVolume)
 
        // First of all, clear all pre-loaded module's module_image, if the 
module
        // isn't in use.
-       hash_iterator iterator;
-       hash_open(sModulesHash, &iterator);
+       ModuleTable::Iterator iterator(sModulesHash);
        struct module* module;
-       while ((module = (struct module*)hash_next(sModulesHash, &iterator))
-                       != NULL) {
+       while (iterator.HasNext()) {
+               module = iterator.Next();
                if (module->ref_count == 0
                        && (module->flags & B_BUILT_IN_MODULE) == 0) {
                        TRACE(("  module %p, \"%s\" unused, clearing image\n", 
module,
@@ -1862,23 +1848,21 @@ module_init_post_boot_device(bool 
bootingFromBootLoaderVolume)
 
        // Now iterate through the images and drop them respectively normalize 
their
        // paths.
-       hash_open(sModuleImagesHash, &iterator);
+       ImageTable::Iterator imageIterator(sModuleImagesHash);
 
        module_image* imagesToReinsert = NULL;
                // When renamed, an image is added to this list to be 
re-entered in the
                // hash at the end. We can't do that during the iteration.
 
-       while (true) {
-               struct module_image* image
-                       = (struct module_image*)hash_next(sModuleImagesHash, 
&iterator);
-               if (image == NULL)
-                       break;
+       while (imageIterator.HasNext()) {
+               struct module_image* image = imageIterator.Next();
 
                if (image->ref_count == 0) {
                        // not in use -- unload it
                        TRACE(("  module image %p, \"%s\" unused, removing\n", 
image,
                                image->path));
-                       hash_remove_current(sModuleImagesHash, &iterator);
+                       // Using RemoveUnchecked to avoid invalidating the 
iterator
+                       sModuleImagesHash->RemoveUnchecked(image);
                        unload_module_image(image, false);
                } else if (bootingFromBootLoaderVolume) {
                        bool pathNormalized = false;
@@ -1934,7 +1918,7 @@ module_init_post_boot_device(bool 
bootingFromBootLoaderVolume)
 
                                // remove the image -- its hash value has 
probably changed,
                                // so we need to re-insert it later
-                               hash_remove_current(sModuleImagesHash, 
&iterator);
+                               sModuleImagesHash->RemoveUnchecked(image);
                                image->next = imagesToReinsert;
                                imagesToReinsert = image;
                        } else {
@@ -1947,7 +1931,7 @@ module_init_post_boot_device(bool 
bootingFromBootLoaderVolume)
        // re-insert the images that have got a new path
        while (module_image* image = imagesToReinsert) {
                imagesToReinsert = image->next;
-               hash_insert(sModuleImagesHash, image);
+               sModuleImagesHash->Insert(image);
        }
 
        TRACE(("module_init_post_boot_device() done\n"));
@@ -2151,22 +2135,18 @@ get_next_loaded_module_name(uint32* _cookie, char* 
buffer, size_t* _bufferSize)
 
        RecursiveLocker _(sModulesLock);
 
-       hash_iterator iterator;
-       hash_open(sModulesHash, &iterator);
-       struct module* module = (struct module*)hash_next(sModulesHash, 
&iterator);
+       ModuleTable::Iterator iterator(sModulesHash);
 
-       for (uint32 i = 0; module != NULL; i++) {
+       for (uint32 i = 0; iterator.HasNext(); i++) {
+               struct module* module = iterator.Next();
                if (i >= offset) {
                        *_bufferSize = strlcpy(buffer, module->name, 
*_bufferSize);
                        *_cookie = i + 1;
                        status = B_OK;
                        break;
                }
-               module = (struct module*)hash_next(sModulesHash, &iterator);
        }
 
-       hash_close(sModulesHash, &iterator, false);
-
        return status;
 }
 
@@ -2185,7 +2165,7 @@ get_module(const char* path, module_info** _info)
 
        RecursiveLocker _(sModulesLock);
 
-       module = (struct module*)hash_lookup(sModulesHash, path);
+       module = sModulesHash->Lookup(path);
 
        // if we don't have it cached yet, search for it
        if (module == NULL || ((module->flags & B_BUILT_IN_MODULE) == 0
@@ -2242,7 +2222,7 @@ put_module(const char* path)
 
        RecursiveLocker _(sModulesLock);
 
-       module = (struct module*)hash_lookup(sModulesHash, path);
+       module = sModulesHash->Lookup(path);
        if (module == NULL) {
                FATAL(("module: We don't seem to have a reference to module 
%s\n",
                        path));

############################################################################

Commit:      79b12613f574cd1a7c9d407b7041e662f02e8700
URL:         http://cgit.haiku-os.org/haiku/commit/?id=79b1261
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Mon Jan 12 14:25:26 2015 UTC

legacy_drivers: convert to BOpenHashTable.

----------------------------------------------------------------------------

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

############################################################################

Commit:      6235b4967bb0a99752efd18eee62a47834c79946
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6235b49
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Mon Jan 12 10:06:03 2015 UTC

More useless inclusions of khash.h

----------------------------------------------------------------------------

diff --git a/headers/private/kernel/Notifications.h 
b/headers/private/kernel/Notifications.h
index 728bbfa..d3ea2fe 100644
--- a/headers/private/kernel/Notifications.h
+++ b/headers/private/kernel/Notifications.h
@@ -14,7 +14,7 @@
 
 #include <lock.h>
 #include <messaging.h>
-#include <util/khash.h>
+#include <util/StringHash.h>
 
 
 #ifdef __cplusplus
diff --git a/src/add-ons/kernel/file_systems/packagefs/indices/Index.h 
b/src/add-ons/kernel/file_systems/packagefs/indices/Index.h
index 7f82ee6..9f7b758 100644
--- a/src/add-ons/kernel/file_systems/packagefs/indices/Index.h
+++ b/src/add-ons/kernel/file_systems/packagefs/indices/Index.h
@@ -10,7 +10,6 @@
 
 #include <SupportDefs.h>
 
-#include <util/khash.h>
 #include <util/OpenHashTable.h>
 
 #include "String.h"
diff --git a/src/add-ons/kernel/file_systems/packagefs/nodes/Node.h 
b/src/add-ons/kernel/file_systems/packagefs/nodes/Node.h
index a1e7271..d4f0764 100644
--- a/src/add-ons/kernel/file_systems/packagefs/nodes/Node.h
+++ b/src/add-ons/kernel/file_systems/packagefs/nodes/Node.h
@@ -13,7 +13,6 @@
 
 #include <lock.h>
 #include <util/DoublyLinkedList.h>
-#include <util/khash.h>
 #include <util/OpenHashTable.h>
 
 #include "String.h"
diff --git a/src/add-ons/kernel/file_systems/packagefs/package/Package.h 
b/src/add-ons/kernel/file_systems/packagefs/package/Package.h
index e9def75..b886188 100644
--- a/src/add-ons/kernel/file_systems/packagefs/package/Package.h
+++ b/src/add-ons/kernel/file_systems/packagefs/package/Package.h
@@ -12,8 +12,8 @@
 #include <Referenceable.h>
 
 #include <util/DoublyLinkedList.h>
-#include <util/khash.h>
 #include <util/OpenHashTable.h>
+#include <util/StringHash.h>
 
 #include <lock.h>
 
diff --git 
a/src/add-ons/kernel/file_systems/packagefs/resolvables/DependencyFamily.h 
b/src/add-ons/kernel/file_systems/packagefs/resolvables/DependencyFamily.h
index 25cd459..3aeb5a7 100644
--- a/src/add-ons/kernel/file_systems/packagefs/resolvables/DependencyFamily.h
+++ b/src/add-ons/kernel/file_systems/packagefs/resolvables/DependencyFamily.h
@@ -6,7 +6,6 @@
 #define DEPENDENCY_FAMILY_H
 
 
-#include <util/khash.h>
 #include <util/OpenHashTable.h>
 
 #include "Dependency.h"
diff --git 
a/src/add-ons/kernel/file_systems/packagefs/resolvables/ResolvableFamily.h 
b/src/add-ons/kernel/file_systems/packagefs/resolvables/ResolvableFamily.h
index d5d8d64..3fb41d1 100644
--- a/src/add-ons/kernel/file_systems/packagefs/resolvables/ResolvableFamily.h
+++ b/src/add-ons/kernel/file_systems/packagefs/resolvables/ResolvableFamily.h
@@ -6,7 +6,6 @@
 #define RESOLVABLE_FAMILY_H
 
 
-#include <util/khash.h>
 #include <util/OpenHashTable.h>
 
 #include "Resolvable.h"
diff --git a/src/add-ons/kernel/file_systems/packagefs/util/StringPool.h 
b/src/add-ons/kernel/file_systems/packagefs/util/StringPool.h
index 2a97b2a..f0b5aec 100644
--- a/src/add-ons/kernel/file_systems/packagefs/util/StringPool.h
+++ b/src/add-ons/kernel/file_systems/packagefs/util/StringPool.h
@@ -14,8 +14,8 @@
 #include <new>
 
 #include <util/AutoLock.h>
-#include <util/khash.h>
 #include <util/OpenHashTable.h>
+#include <util/StringHash.h>
 
 
 class StringData;
diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 
b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp
index 8c3fae3..b0da601 100644
--- a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp
+++ b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp
@@ -31,7 +31,6 @@
 #include <lock.h>
 #include <tracing.h>
 #include <util/AutoLock.h>
-#include <util/khash.h>
 #include <util/list.h>
 
 #include "EndpointManager.h"
diff --git a/src/add-ons/kernel/network/protocols/tcp/tcp.h 
b/src/add-ons/kernel/network/protocols/tcp/tcp.h
index 583d32b..64e13ac 100644
--- a/src/add-ons/kernel/network/protocols/tcp/tcp.h
+++ b/src/add-ons/kernel/network/protocols/tcp/tcp.h
@@ -16,8 +16,6 @@
 #include <net_socket.h>
 #include <net_stack.h>
 
-#include <util/khash.h>
-
 #include <ByteOrder.h>
 
 #include <sys/socket.h>
diff --git a/src/add-ons/kernel/network/protocols/unix/UnixAddress.cpp 
b/src/add-ons/kernel/network/protocols/unix/UnixAddress.cpp
index 9a3154a..12fcb3a 100644
--- a/src/add-ons/kernel/network/protocols/unix/UnixAddress.cpp
+++ b/src/add-ons/kernel/network/protocols/unix/UnixAddress.cpp
@@ -9,7 +9,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <util/khash.h>
+#include <util/StringHash.h>
 
 #include <net_datalink.h>
 #include <NetUtilities.h>
diff --git a/src/system/kernel/fs/EntryCache.h 
b/src/system/kernel/fs/EntryCache.h
index e197426..79a8df0 100644
--- a/src/system/kernel/fs/EntryCache.h
+++ b/src/system/kernel/fs/EntryCache.h
@@ -9,8 +9,8 @@
 #include <stdlib.h>
 
 #include <util/AutoLock.h>
-#include <util/khash.h>
 #include <util/OpenHashTable.h>
+#include <util/StringHash.h>
 
 
 struct EntryCacheKey {
diff --git a/src/system/kernel/fs/fifo.cpp b/src/system/kernel/fs/fifo.cpp
index 15d45ff..e7e9f2c 100644
--- a/src/system/kernel/fs/fifo.cpp
+++ b/src/system/kernel/fs/fifo.cpp
@@ -22,7 +22,6 @@
 
 #include <condition_variable.h>
 #include <debug_hex_dump.h>
-#include <khash.h>
 #include <lock.h>
 #include <select_sync_pool.h>
 #include <syscall_restart.h>
@@ -44,9 +43,6 @@
 #endif
 
 
-#define PIPEFS_HASH_SIZE               16
-
-
 namespace fifo {
 
 
diff --git a/src/system/kernel/fs/node_monitor.cpp 
b/src/system/kernel/fs/node_monitor.cpp
index ae5e66e..95f1641 100644
--- a/src/system/kernel/fs/node_monitor.cpp
+++ b/src/system/kernel/fs/node_monitor.cpp
@@ -16,7 +16,6 @@
 #include <NodeMonitor.h>
 
 #include <fd.h>
-#include <khash.h>
 #include <lock.h>
 #include <messaging.h>
 #include <Notifications.h>

############################################################################

Commit:      f9defd45266aef2138460ad8d719b452b3a158bc
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f9defd4
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Mon Jan 12 16:47:02 2015 UTC

VFS: migrate to BOpenHashTable.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp
index 845912c..5acca18 100644
--- a/src/system/kernel/fs/vfs.cpp
+++ b/src/system/kernel/fs/vfs.cpp
@@ -40,7 +40,6 @@
 #include <fd.h>
 #include <file_cache.h>
 #include <fs/node_monitor.h>
-#include <khash.h>
 #include <KPath.h>
 #include <lock.h>
 #include <low_resource_manager.h>
@@ -252,12 +251,73 @@ static rw_lock sVnodeLock = 
RW_LOCK_INITIALIZER("vfs_vnode_lock");
 static mutex sIOContextRootLock = MUTEX_INITIALIZER("io_context::root lock");
 
 
+struct VnodeHash {
+       typedef vnode_hash_key  KeyType;
+       typedef struct vnode    ValueType;
+
+#define VHASH(mountid, vnodeid) \
+       (((uint32)((vnodeid) >> 32) + (uint32)(vnodeid)) ^ (uint32)(mountid))
+
+       size_t HashKey(KeyType key) const
+       {
+               return VHASH(key.device, key.vnode);
+       }
+
+       size_t Hash(ValueType* vnode) const
+       {
+               return VHASH(vnode->device, vnode->id);
+       }
+
+#undef VHASH
+
+       bool Compare(KeyType key, ValueType* vnode) const
+       {
+               return vnode->device == key.device && vnode->id == key.vnode;
+       }
+
+       ValueType*& GetLink(ValueType* value) const
+       {
+               return value->next;
+       }
+};
+
+typedef BOpenHashTable<VnodeHash> VnodeTable;
+
+
+struct MountHash {
+       typedef dev_t                   KeyType;
+       typedef struct fs_mount ValueType;
+
+       size_t HashKey(KeyType key) const
+       {
+               return key;
+       }
+
+       size_t Hash(ValueType* mount) const
+       {
+               return mount->id;
+       }
+
+       bool Compare(KeyType key, ValueType* mount) const
+       {
+               return mount->id == key;
+       }
+
+       ValueType*& GetLink(ValueType* value) const
+       {
+               return value->next;
+       }
+};
+
+typedef BOpenHashTable<MountHash> MountTable;
+
+
 #define VNODE_HASH_TABLE_SIZE 1024
-static hash_table* sVnodeTable;
+static VnodeTable* sVnodeTable;
 static struct vnode* sRoot;
 
 #define MOUNTS_HASH_TABLE_SIZE 16
-static hash_table* sMountsTable;
+static MountTable* sMountsTable;
 static dev_t sNextMountID = 1;
 
 #define MAX_TEMP_IO_VECS 8
@@ -647,32 +707,6 @@ public:
 #endif // VFS_PAGES_IO_TRACING
 
 
-static int
-mount_compare(void* _m, const void* _key)
-{
-       struct fs_mount* mount = (fs_mount*)_m;
-       const dev_t* id = (dev_t*)_key;
-
-       if (mount->id == *id)
-               return 0;
-
-       return -1;
-}
-
-
-static uint32
-mount_hash(void* _m, const void* _key, uint32 range)
-{
-       struct fs_mount* mount = (fs_mount*)_m;
-       const dev_t* id = (dev_t*)_key;
-
-       if (mount)
-               return mount->id % range;
-
-       return (uint32)*id % range;
-}
-
-
 /*! Finds the mounted device (the fs_mount structure) with the given ID.
        Note, you must hold the gMountMutex lock when you call this function.
 */
@@ -681,7 +715,7 @@ find_mount(dev_t id)
 {
        ASSERT_LOCKED_MUTEX(&sMountMutex);
 
-       return (fs_mount*)hash_lookup(sMountsTable, (void*)&id);
+       return sMountsTable->Lookup(id);
 }
 
 
@@ -809,37 +843,6 @@ get_file_system_name_for_layer(const char* fsNames, int32 
layer)
 }
 
 
-static int
-vnode_compare(void* _vnode, const void* _key)
-{
-       struct vnode* vnode = (struct vnode*)_vnode;
-       const struct vnode_hash_key* key = (vnode_hash_key*)_key;
-
-       if (vnode->device == key->device && vnode->id == key->vnode)
-               return 0;
-
-       return -1;
-}
-
-
-static uint32
-vnode_hash(void* _vnode, const void* _key, uint32 range)
-{
-       struct vnode* vnode = (struct vnode*)_vnode;
-       const struct vnode_hash_key* key = (vnode_hash_key*)_key;
-
-#define VHASH(mountid, vnodeid) \
-       (((uint32)((vnodeid) >> 32) + (uint32)(vnodeid)) ^ (uint32)(mountid))
-
-       if (vnode != NULL)
-               return VHASH(vnode->device, vnode->id) % range;
-
-       return VHASH(key->device, key->vnode) % range;
-
-#undef VHASH
-}
-
-
 static void
 add_vnode_to_mount_list(struct vnode* vnode, struct fs_mount* mount)
 {
@@ -874,7 +877,7 @@ lookup_vnode(dev_t mountID, ino_t vnodeID)
        key.device = mountID;
        key.vnode = vnodeID;
 
-       return (vnode*)hash_lookup(sVnodeTable, &key);
+       return sVnodeTable->Lookup(key);
 }
 
 
@@ -933,7 +936,7 @@ create_new_vnode_and_lock(dev_t mountID, ino_t vnodeID, 
struct vnode*& _vnode,
        }
 
        // add the vnode to the mount's node list and the hash table
-       hash_insert(sVnodeTable, vnode);
+       sVnodeTable->Insert(vnode);
        add_vnode_to_mount_list(vnode, vnode->mount);
 
        mutex_unlock(&sMountMutex);
@@ -993,7 +996,7 @@ free_vnode(struct vnode* vnode, bool reenter)
        // The file system has removed the resources of the vnode now, so we can
        // make it available again (by removing the busy vnode from the hash).
        rw_lock_write_lock(&sVnodeLock);
-       hash_remove(sVnodeTable, vnode);
+       sVnodeTable->Remove(vnode);
        rw_lock_write_unlock(&sVnodeLock);
 
        // if we have a VMCache attached, remove it
@@ -1205,7 +1208,7 @@ restart:
                                FS_CALL(vnode, put_vnode, reenter);
 
                        rw_lock_write_lock(&sVnodeLock);
-                       hash_remove(sVnodeTable, vnode);
+                       sVnodeTable->Remove(vnode);
                        remove_vnode_from_mount_list(vnode, vnode->mount);
                        rw_lock_write_unlock(&sVnodeLock);
 
@@ -3149,7 +3152,7 @@ dump_mount(int argc, char** argv)
        ulong val = parse_expression(argv[1]);
        uint32 id = val;
 
-       struct fs_mount* mount = (fs_mount*)hash_lookup(sMountsTable, 
(void*)&id);
+       struct fs_mount* mount = sMountsTable->Lookup(id);
        if (mount == NULL) {
                if (IS_USER_ADDRESS(id)) {
                        kprintf("fs_mount not found\n");
@@ -3175,12 +3178,11 @@ dump_mounts(int argc, char** argv)
                B_PRINTF_POINTER_WIDTH, "address", B_PRINTF_POINTER_WIDTH, 
"root",
                B_PRINTF_POINTER_WIDTH, "covers", B_PRINTF_POINTER_WIDTH, 
"cookie");
 
-       struct hash_iterator iterator;
        struct fs_mount* mount;
 
-       hash_open(sMountsTable, &iterator);
-       while ((mount = (struct fs_mount*)hash_next(sMountsTable, &iterator))
-                       != NULL) {
+       MountTable::Iterator iterator(sMountsTable);
+       while (iterator.HasNext()) {
+               mount = iterator.Next();
                kprintf("%p%4" B_PRIdDEV " %p %p %p %s\n", mount, mount->id, 
mount->root_vnode,
                        mount->root_vnode->covers, 
mount->volume->private_volume,
                        mount->volume->file_system_name);
@@ -3193,7 +3195,6 @@ dump_mounts(int argc, char** argv)
                }
        }
 
-       hash_close(sMountsTable, &iterator, false);
        return 0;
 }
 
@@ -3225,19 +3226,18 @@ dump_vnode(int argc, char** argv)
                return 0;
        }
 
-       struct hash_iterator iterator;
        dev_t device = parse_expression(argv[argi]);
        ino_t id = parse_expression(argv[argi + 1]);
 
-       hash_open(sVnodeTable, &iterator);
-       while ((vnode = (struct vnode*)hash_next(sVnodeTable, &iterator)) != 
NULL) {
+       VnodeTable::Iterator iterator(sVnodeTable);
+       while (iterator.HasNext()) {
+               vnode = iterator.Next();
                if (vnode->id != id || vnode->device != device)
                        continue;
 
                _dump_vnode(vnode, printPath);
        }
 
-       hash_close(sVnodeTable, &iterator, false);
        return 0;
 }
 
@@ -3253,15 +3253,15 @@ dump_vnodes(int argc, char** argv)
        // restrict dumped nodes to a certain device if requested
        dev_t device = parse_expression(argv[1]);
 
-       struct hash_iterator iterator;
        struct vnode* vnode;
 
        kprintf("%-*s   dev     inode  ref %-*s   %-*s   %-*s   flags\n",
                B_PRINTF_POINTER_WIDTH, "address", B_PRINTF_POINTER_WIDTH, 
"cache",
                B_PRINTF_POINTER_WIDTH, "fs-node", B_PRINTF_POINTER_WIDTH, 
"locking");
 
-       hash_open(sVnodeTable, &iterator);
-       while ((vnode = (struct vnode*)hash_next(sVnodeTable, &iterator)) != 
NULL) {
+       VnodeTable::Iterator iterator(sVnodeTable);
+       while (iterator.HasNext()) {
+               vnode = iterator.Next();
                if (vnode->device != device)
                        continue;
 
@@ -3272,7 +3272,6 @@ dump_vnodes(int argc, char** argv)
                        vnode->IsUnpublished() ? "u" : "-");
        }
 
-       hash_close(sVnodeTable, &iterator, false);
        return 0;
 }
 
@@ -3280,7 +3279,6 @@ dump_vnodes(int argc, char** argv)
 static int
 dump_vnode_caches(int argc, char** argv)
 {
-       struct hash_iterator iterator;
        struct vnode* vnode;
 
        if (argc > 2 || !strcmp(argv[1], "--help")) {
@@ -3296,8 +3294,9 @@ dump_vnode_caches(int argc, char** argv)
        kprintf("%-*s   dev     inode %-*s       size   pages\n",
                B_PRINTF_POINTER_WIDTH, "address", B_PRINTF_POINTER_WIDTH, 
"cache");
 
-       hash_open(sVnodeTable, &iterator);
-       while ((vnode = (struct vnode*)hash_next(sVnodeTable, &iterator)) != 
NULL) {
+       VnodeTable::Iterator iterator(sVnodeTable);
+       while (iterator.HasNext()) {
+               vnode = iterator.Next();
                if (vnode->cache == NULL)
                        continue;
                if (device != -1 && vnode->device != device)
@@ -3309,7 +3308,6 @@ dump_vnode_caches(int argc, char** argv)
                        vnode->cache->page_count);
        }
 
-       hash_close(sVnodeTable, &iterator, false);
        return 0;
 }
 
@@ -3384,16 +3382,7 @@ dump_vnode_usage(int argc, char** argv)
        kprintf("Unused vnodes: %" B_PRIu32 " (max unused %" B_PRIu32 ")\n",
                sUnusedVnodes, kMaxUnusedVnodes);
 
-       struct hash_iterator iterator;
-       hash_open(sVnodeTable, &iterator);
-
-       uint32 count = 0;
-       struct vnode* vnode;
-       while ((vnode = (struct vnode*)hash_next(sVnodeTable, &iterator)) != 
NULL) {
-               count++;
-       }
-
-       hash_close(sVnodeTable, &iterator, false);
+       uint32 count = sVnodeTable->CountElements();
 
        kprintf("%" B_PRIu32 " vnodes total (%" B_PRIu32 " in use).\n", count,
                count - sUnusedVnodes);
@@ -3727,7 +3716,7 @@ publish_vnode(fs_volume* volume, ino_t vnodeID, void* 
privateNode,
                        vnode->SetUnpublished(false);
                } else {
                        locker.Lock();
-                       hash_remove(sVnodeTable, vnode);
+                       sVnodeTable->Remove(vnode);
                        remove_vnode_from_mount_list(vnode, vnode->mount);
                        free(vnode);
                }
@@ -5155,18 +5144,16 @@ vfs_init(kernel_args* args)
 {
        vnode::StaticInit();
 
-       struct vnode dummyVnode;
-       sVnodeTable = hash_init(VNODE_HASH_TABLE_SIZE,
-               offset_of_member(dummyVnode, next), &vnode_compare, 
&vnode_hash);
-       if (sVnodeTable == NULL)
+       sVnodeTable = new(std::nothrow) VnodeTable();
+       if (sVnodeTable == NULL | sVnodeTable->Init(VNODE_HASH_TABLE_SIZE) != 
B_OK)
                panic("vfs_init: error creating vnode hash table\n");
 
-       list_init_etc(&sUnusedVnodeList, offset_of_member(dummyVnode, 
unused_link));
+       list_init_etc(&sUnusedVnodeList, offsetof(struct vnode, unused_link));
 
        struct fs_mount dummyMount;
-       sMountsTable = hash_init(MOUNTS_HASH_TABLE_SIZE,
-               offset_of_member(dummyMount, next), &mount_compare, 
&mount_hash);
-       if (sMountsTable == NULL)
+       sMountsTable = new(std::nothrow) MountTable();
+       if (sMountsTable == NULL
+                       || sMountsTable->Init(MOUNTS_HASH_TABLE_SIZE) != B_OK)
                panic("vfs_init: error creating mounts hash table\n");
 
        node_monitor_init();
@@ -7375,7 +7362,7 @@ fs_mount(char* path, const char* device, const char* 
fsName, uint32 flags,
        // insert mount struct into list before we call FS's mount() function
        // so that vnodes can be created for this mount
        mutex_lock(&sMountMutex);
-       hash_insert(sMountsTable, mount);
+       sMountsTable->Insert(mount);
        mutex_unlock(&sMountMutex);
 
        ino_t rootID;
@@ -7492,7 +7479,7 @@ err3:
                put_vnode(coveredNode);
 err2:
        mutex_lock(&sMountMutex);
-       hash_remove(sMountsTable, mount);
+       sMountsTable->Remove(mount);
        mutex_unlock(&sMountMutex);
 err1:
        delete mount;
@@ -7700,7 +7687,7 @@ fs_unmount(char* path, dev_t mountID, uint32 flags, bool 
kernel)
 
        // remove the mount structure from the hash table
        mutex_lock(&sMountMutex);
-       hash_remove(sMountsTable, mount);
+       sMountsTable->Remove(mount);
        mutex_unlock(&sMountMutex);
 
        mountOpLocker.Unlock();

############################################################################

Revision:    hrev48666
Commit:      63fdcb8e7e09f975bd53e7fc18bc9ff3cfe1294c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=63fdcb8
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Mon Jan 12 17:20:22 2015 UTC

ext2: migrate to BOpenHashTable.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/file_systems/ext2/HashRevokeManager.cpp 
b/src/add-ons/kernel/file_systems/ext2/HashRevokeManager.cpp
index 10f3981..9f76ece 100644
--- a/src/add-ons/kernel/file_systems/ext2/HashRevokeManager.cpp
+++ b/src/add-ons/kernel/file_systems/ext2/HashRevokeManager.cpp
@@ -33,16 +33,16 @@ HashRevokeManager::~HashRevokeManager()
 {
        if (fHash != NULL) {
                if (fRevokeCount != 0) {
-                       RevokeElement *element =
-                               (RevokeElement*)hash_remove_first(fHash, NULL);
+                       RevokeElement *element = fHash->Clear(true);
 
                        while (element != NULL) {
+                               RevokeElement* next = element->next;
                                delete element;
-                               element = 
(RevokeElement*)hash_remove_first(fHash, NULL);
+                               element = next;
                        }
                }
 
-               hash_uninit(fHash);
+               delete fHash;
        }
 }
 
@@ -50,13 +50,9 @@ HashRevokeManager::~HashRevokeManager()
 status_t
 HashRevokeManager::Init()
 {
-       RevokeElement dummyElement;
-       
-       fHash = hash_init(kInitialHashSize, offset_of_member(dummyElement, 
next),
-               &HashRevokeManager::Compare,
-               &HashRevokeManager::Hash);
+       fHash = new(std::nothrow) RevokeTable();
 
-       if (fHash == NULL)
+       if (fHash == NULL || fHash->Init(kInitialHashSize) != B_OK)
                return B_NO_MEMORY;
 
        return B_OK;
@@ -66,20 +62,19 @@ HashRevokeManager::Init()
 status_t
 HashRevokeManager::Insert(uint32 block, uint32 commitID)
 {
-       RevokeElement* element = (RevokeElement*)hash_lookup(fHash, &block);
+       RevokeElement* element = fHash->Lookup(block);
    
        if (element != NULL) {
                TRACE("HashRevokeManager::Insert(): Already has an element\n");
                if (element->commitID < commitID) {
                        TRACE("HashRevokeManager::Insert(): Deleting previous 
element\n");
-                       status_t retValue = hash_remove(fHash, element);
+                       bool retValue = fHash->Remove(element);
                        
-                       if (retValue != B_OK)
-                               return retValue;
+                       if (!retValue)
+                               return B_ERROR;
 
                        delete element;
-               }
-               else {
+               } else {
                        return B_OK;
                                // We already have a newer version of the block
                }
@@ -92,24 +87,24 @@ HashRevokeManager::Insert(uint32 block, uint32 commitID)
 status_t
 HashRevokeManager::Remove(uint32 block)
 {
-       RevokeElement* element = (RevokeElement*)hash_lookup(fHash, &block);
+       RevokeElement* element = fHash->Lookup(block);
 
        if (element == NULL)
                return B_ERROR; // TODO: Perhaps we should just ignore?
 
-       status_t retValue = hash_remove(fHash, element);
+       bool retValue = fHash->Remove(element);
        
-       if (retValue == B_OK)
+       if (retValue)
                delete element;
 
-       return retValue;
+       return B_ERROR;
 }
 
 
 bool
 HashRevokeManager::Lookup(uint32 block, uint32 commitID)
 {
-       RevokeElement* element = (RevokeElement*)hash_lookup(fHash, &block);
+       RevokeElement* element = fHash->Lookup(block);
 
        if (element == NULL)
                return false;
@@ -157,7 +152,7 @@ HashRevokeManager::_ForceInsert(uint32 block, uint32 
commitID)
        element->block = block;
        element->commitID = commitID;
 
-       status_t retValue = hash_insert_grow(fHash, element);
+       status_t retValue = fHash->Insert(element);
 
        if (retValue == B_OK) {
                fRevokeCount++;
diff --git a/src/add-ons/kernel/file_systems/ext2/HashRevokeManager.h 
b/src/add-ons/kernel/file_systems/ext2/HashRevokeManager.h
index ab1f3c4..0be41ab 100644
--- a/src/add-ons/kernel/file_systems/ext2/HashRevokeManager.h
+++ b/src/add-ons/kernel/file_systems/ext2/HashRevokeManager.h
@@ -8,7 +8,7 @@
 #ifndef HASHREVOKEMANAGER_H
 #define HASHREVOKEMANAGER_H
 
-#include <util/khash.h>
+#include <util/OpenHashTable.h>
 
 #include "RevokeManager.h"
 
@@ -20,6 +20,35 @@ struct RevokeElement {
 };
 
 
+struct RevokeHash {
+               typedef uint32                  KeyType;
+               typedef RevokeElement   ValueType;
+
+               size_t HashKey(KeyType key) const
+               {
+                       return key;
+               }
+
+               size_t Hash(ValueType* value) const
+               {
+                       return HashKey(value->block);
+               }
+
+               bool Compare(KeyType key, ValueType* value) const
+               {
+                       return value->block == key;
+               }
+
+               ValueType*& GetLink(ValueType* value) const
+               {
+                       return value->next;
+               }
+
+};
+
+typedef BOpenHashTable<RevokeHash> RevokeTable;
+
+
 class HashRevokeManager : public RevokeManager {
 public:
                                                HashRevokeManager();
@@ -30,7 +59,7 @@ public:
        virtual status_t        Insert(uint32 block, uint32 commitID);
        virtual status_t        Remove(uint32 block);
        virtual bool            Lookup(uint32 block, uint32 commitID);
-                       
+
        static  int                     Compare(void* element, const void* key);
        static  uint32          Hash(void* element, const void* key, uint32 
range);
 
@@ -38,7 +67,7 @@ protected:
                        status_t        _ForceInsert(uint32 block, uint32 
commitID);
 
 private:
-                       hash_table*     fHash;
+                       RevokeTable*    fHash;
 
        const   int                     kInitialHashSize;
 };


Other related posts: