diff --git a/src/system/kernel/device_manager/legacy_drivers.cpp b/src/system/kernel/device_manager/legacy_drivers.cpp index 3ffd1f6cbd..c395b250be 100644 --- a/src/system/kernel/device_manager/legacy_drivers.cpp +++ b/src/system/kernel/device_manager/legacy_drivers.cpp @@ -196,6 +196,7 @@ static int32 sDriverEvents; static EntryList sDriversToAdd; static EntryList sDriversToRemove; static mutex sDriversListLock = MUTEX_INITIALIZER("driversList"); + // inner lock, protects the sDriversToAdd/sDriversToRemove lists only static DirectoryWatcher sDirectoryWatcher; static DirectoryNodeHash sDirectoryNodeHash; static recursive_lock sLock; @@ -641,14 +642,19 @@ handle_driver_events(void */*_fs*/, int /*iteration*/) // something happened, let's see what it was - RecursiveLocker locker(sLock); - MutexLocker _(sDriversListLock); + RecursiveLocker _(sLock); + + // Add new drivers while (true) { + MutexLocker listLocker(sDriversListLock); + path_entry* path = sDriversToAdd.RemoveHead(); if (path == NULL) break; + listLocker.Unlock(); + legacy_driver* driver = (legacy_driver*)hash_lookup(sDriverHash, get_leaf(path->path)); if (driver == NULL) @@ -657,11 +663,18 @@ handle_driver_events(void */*_fs*/, int /*iteration*/) driver->binary_updated = true; delete path; } + + // Mark removed drivers as updated + while (true) { + MutexLocker listLocker(sDriversListLock); + path_entry* path = sDriversToRemove.RemoveHead(); if (path == NULL) break; + listLocker.Unlock(); + legacy_driver* driver = (legacy_driver*)hash_lookup(sDriverHash, get_leaf(path->path)); if (driver != NULL && get_priority(path->path) >= driver->priority) @@ -669,6 +682,8 @@ handle_driver_events(void */*_fs*/, int /*iteration*/) delete path; } + // Reload updated drivers + hash_iterator iterator; hash_open(sDriverHash, &iterator); legacy_driver *driver;