Ticket #7039: 0001-Change-the-monitor_lock-to-be-a-recursive_lock-fixin.patch

File 0001-Change-the-monitor_lock-to-be-a-recursive_lock-fixin.patch, 4.0 KB (added by jackburton, 6 years ago)
  • src/add-ons/kernel/network/stack/device_interfaces.cpp

    From dff920765002d07c2275ef390368fc43bc08f00b Mon Sep 17 00:00:00 2001
    From: Stefano Ceccherini <stefano.ceccherini@gmail.com>
    Date: Sat, 6 Sep 2014 21:13:19 +0200
    Subject: [PATCH 1/2] Change the monitor_lock to be a recursive_lock, fixing
     #7039. notify_device_monitor acquires the monitor lock, then tells the
     monitor to unregister itself, calling unregister_device_monitor, which
     acquires the monitor lock again.
    
    ---
     src/add-ons/kernel/network/stack/device_interfaces.cpp | 16 ++++++++--------
     src/add-ons/kernel/network/stack/device_interfaces.h   |  2 +-
     2 files changed, 9 insertions(+), 9 deletions(-)
    
    diff --git a/src/add-ons/kernel/network/stack/device_interfaces.cpp b/src/add-ons/kernel/network/stack/device_interfaces.cpp
    index a3030f0..0143360 100644
    a b allocate_device_interface(net_device* device, net_device_module_info* module)  
    171171        return NULL;
    172172
    173173    recursive_lock_init(&interface->receive_lock, "device interface receive");
    174     mutex_init(&interface->monitor_lock, "device interface monitors");
     174    recursive_lock_init(&interface->monitor_lock, "device interface monitors");
    175175
    176176    char name[128];
    177177    snprintf(name, sizeof(name), "%s receive queue", device->name);
    error2:  
    206206    uninit_fifo(&interface->receive_queue);
    207207error1:
    208208    recursive_lock_destroy(&interface->receive_lock);
    209     mutex_destroy(&interface->monitor_lock);
     209    recursive_lock_destroy(&interface->monitor_lock);
    210210    delete interface;
    211211
    212212    return NULL;
    error1:  
    216216static void
    217217notify_device_monitors(net_device_interface* interface, int32 event)
    218218{
    219     MutexLocker locker(interface->monitor_lock);
     219    RecursiveLocker locker(interface->monitor_lock);
    220220
    221221    DeviceMonitorList::Iterator iterator
    222222        = interface->monitor_funcs.GetIterator();
    put_device_interface(struct net_device_interface* interface)  
    392392    device->module->uninit_device(device);
    393393    put_module(moduleName);
    394394
    395     mutex_destroy(&interface->monitor_lock);
     395    recursive_lock_destroy(&interface->monitor_lock);
    396396    recursive_lock_destroy(&interface->receive_lock);
    397397    delete interface;
    398398}
    void  
    478478device_interface_monitor_receive(net_device_interface* interface,
    479479    net_buffer* buffer)
    480480{
    481     MutexLocker locker(interface->monitor_lock);
     481    RecursiveLocker locker(interface->monitor_lock);
    482482
    483483    DeviceMonitorList::Iterator iterator
    484484        = interface->monitor_funcs.GetIterator();
    register_device_monitor(net_device* device, net_device_monitor* monitor)  
    706706    if (interface == NULL)
    707707        return B_DEVICE_NOT_FOUND;
    708708
    709     MutexLocker monitorLocker(interface->monitor_lock);
     709    RecursiveLocker monitorLocker(interface->monitor_lock);
    710710    interface->monitor_funcs.Add(monitor);
    711711    atomic_add(&interface->monitor_count, 1);
    712712
    unregister_device_monitor(net_device* device, net_device_monitor* monitor)  
    725725    if (interface == NULL)
    726726        return B_DEVICE_NOT_FOUND;
    727727
    728     MutexLocker monitorLocker(interface->monitor_lock);
     728    RecursiveLocker monitorLocker(interface->monitor_lock);
    729729
    730730    // search for the monitor
    731731
    device_removed(net_device* device)  
    776776
    777777    // By now all of the monitors must have removed themselves. If they
    778778    // didn't, they'll probably wait forever to be callback'ed again.
    779     mutex_lock(&interface->monitor_lock);
     779    recursive_lock_lock(&interface->monitor_lock);
    780780    interface->monitor_funcs.RemoveAll();
    781781
    782782    // All of the readers should be gone as well since we are out of
  • src/add-ons/kernel/network/stack/device_interfaces.h

    diff --git a/src/add-ons/kernel/network/stack/device_interfaces.h b/src/add-ons/kernel/network/stack/device_interfaces.h
    index 6dcc4c0..958448e 100644
    a b struct net_device_interface : DoublyLinkedListLinkImpl<net_device_interface> {  
    3737    int32               deframe_ref_count;
    3838
    3939    int32               monitor_count;
    40     mutex               monitor_lock;
     40    recursive_lock          monitor_lock;
    4141    DeviceMonitorList   monitor_funcs;
    4242
    4343    DeviceHandlerList   receive_funcs;