Ticket #3447: legacy_drivers.diff

File legacy_drivers.diff, 3.2 KB (added by korli, 16 years ago)
  • src/system/kernel/device_manager/legacy_drivers.cpp

     
    185185static DriverWatcher sDriverWatcher;
    186186static int32 sDriverEvents;
    187187static DoublyLinkedList<path_entry> sDriversToAdd;
     188static DoublyLinkedList<path_entry> sDriversToRemove;
     189static mutex sDriversListLock = MUTEX_INITIALIZER("driversList");
    188190static DirectoryWatcher sDirectoryWatcher;
    189191static DirectoryNodeHash sDirectoryNodeHash;
    190192static recursive_lock sLock;
     
    620622    // something happened, let's see what it was
    621623
    622624    RecursiveLocker locker(sLock);
     625    MutexLocker _(sDriversListLock);
    623626
    624627    while (true) {
    625628        path_entry* path = sDriversToAdd.RemoveHead();
    626629        if (path == NULL)
    627630            break;
    628631
    629         legacy_driver_add(path->path);
     632        legacy_driver* driver = (legacy_driver*)hash_lookup(sDriverHash,
     633            get_leaf(path->path));
     634        if (driver == NULL)
     635            legacy_driver_add(path->path);
     636        else if (get_priority(path->path) >= driver->priority)
     637            driver->binary_updated = true;
    630638        delete path;
    631639    }
     640    while (true) {
     641        path_entry* path = sDriversToRemove.RemoveHead();
     642        if (path == NULL)
     643            break;
    632644
     645        legacy_driver* driver = (legacy_driver*)hash_lookup(sDriverHash,
     646            get_leaf(path->path));
     647        if (driver != NULL && get_priority(path->path) >= driver->priority)
     648            driver->binary_updated = true;
     649        delete path;
     650    }
     651
    633652    hash_iterator iterator;
    634653    hash_open(sDriverHash, &iterator);
    635654    legacy_driver *driver;
     
    648667}
    649668
    650669
    651 static void
    652 driver_added(const char* path)
    653 {
    654     int32 priority = get_priority(path);
    655     RecursiveLocker locker(sLock);
    656 
    657     legacy_driver* driver = (legacy_driver*)hash_lookup(sDriverHash,
    658         get_leaf(path));
    659 
    660     if (driver == NULL) {
    661         // Add the driver to our list
    662         path_entry* entry = new(std::nothrow) path_entry;
    663         if (entry == NULL)
    664             return;
    665 
    666         strlcpy(entry->path, path, sizeof(entry->path));
    667         sDriversToAdd.Add(entry);
    668     } else {
    669         // Update the driver if it is affected by the new entry
    670         if (priority < driver->priority)
    671             return;
    672 
    673         driver->binary_updated = true;
    674     }
    675 
    676     atomic_add(&sDriverEvents, 1);
    677 }
    678 
    679 
    680 static void
    681 driver_removed(const char* path)
    682 {
    683     int32 priority = get_priority(path);
    684     RecursiveLocker locker(sLock);
    685 
    686     legacy_driver* driver = (legacy_driver*)hash_lookup(sDriverHash,
    687         get_leaf(path));
    688     if (driver == NULL || priority < driver->priority)
    689         return;
    690 
    691     driver->binary_updated = true;
    692     atomic_add(&sDriverEvents, 1);
    693 }
    694 
    695 
    696670//  #pragma mark - DriverWatcher
    697671
    698672
     
    974948    dprintf("driver \"%s\" %s\n", path.Leaf(),
    975949        opcode == B_ENTRY_CREATED ? "added" : "removed");
    976950
     951    path_entry* entry = new(std::nothrow) path_entry;
     952    if (entry == NULL)
     953        return;
     954
     955    strlcpy(entry->path, path.Path(), sizeof(entry->path));
     956    MutexLocker _(sDriversListLock);
     957
    977958    switch (opcode) {
    978959        case B_ENTRY_CREATED:
    979             driver_added(path.Path());
     960            sDriversToAdd.Add(entry);
    980961            break;
    981962        case B_ENTRY_REMOVED:
    982             driver_removed(path.Path());
     963            sDriversToRemove.Add(entry);
    983964            break;
    984965    }
     966    atomic_add(&sDriverEvents, 1);
    985967}
    986968
    987969