From ddaf034ff89122b7ae165371674e14c492438c58 Mon Sep 17 00:00:00 2001
From: Stefano Ceccherini <stefano.ceccherini@gmail.com>
Date: Mon, 4 Feb 2013 11:30:55 +0100
Subject: [PATCH] Converted the "net_interfaces" mutex into a recursive
locker, and acquire it in Interface::SetDown().
---
src/add-ons/kernel/network/stack/interfaces.cpp | 33 ++++++++++++-----------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/src/add-ons/kernel/network/stack/interfaces.cpp b/src/add-ons/kernel/network/stack/interfaces.cpp
index 9a3c73b..54e7046 100644
a
|
b
|
struct AddressHashDefinition {
|
79 | 79 | typedef BOpenHashTable<AddressHashDefinition, true, false> AddressTable; |
80 | 80 | |
81 | 81 | |
82 | | static mutex sLock; |
| 82 | static recursive_lock sLock; |
83 | 83 | static InterfaceList sInterfaces; |
84 | 84 | static mutex sHashLock; |
85 | 85 | static AddressTable sAddressTable; |
… |
… |
static uint32 sInterfaceIndex;
|
91 | 91 | void |
92 | 92 | dump_interface_refs(void) |
93 | 93 | { |
94 | | MutexLocker locker(sLock); |
| 94 | RecursiveLocker locker(sLock); |
95 | 95 | |
96 | 96 | InterfaceList::Iterator iterator = sInterfaces.GetIterator(); |
97 | 97 | while (Interface* interface = iterator.Next()) { |
… |
… |
Interface::SetDown()
|
933 | 933 | if ((flags & IFF_UP) == 0) |
934 | 934 | return; |
935 | 935 | |
| 936 | RecursiveLocker interfacesLocker(sLock); |
936 | 937 | RecursiveLocker locker(fLock); |
937 | 938 | |
938 | 939 | DatalinkTable::Iterator iterator = fDatalinkTable.GetIterator(); |
… |
… |
Interface::_ChangeAddress(RecursiveLocker& locker, InterfaceAddress* address,
|
1173 | 1174 | static struct Interface* |
1174 | 1175 | find_interface(const char* name) |
1175 | 1176 | { |
1176 | | ASSERT_LOCKED_MUTEX(&sLock); |
| 1177 | ASSERT_LOCKED_RECURSIVE(&sLock); |
1177 | 1178 | |
1178 | 1179 | InterfaceList::Iterator iterator = sInterfaces.GetIterator(); |
1179 | 1180 | while (Interface* interface = iterator.Next()) { |
… |
… |
status_t
|
1208 | 1209 | add_interface(const char* name, net_domain_private* domain, |
1209 | 1210 | const ifaliasreq& request, net_device_interface* deviceInterface) |
1210 | 1211 | { |
1211 | | MutexLocker locker(sLock); |
| 1212 | RecursiveLocker locker(sLock); |
1212 | 1213 | |
1213 | 1214 | if (find_interface(name) != NULL) |
1214 | 1215 | return B_NAME_IN_USE; |
… |
… |
remove_interface(Interface* interface)
|
1249 | 1250 | interface->SetDown(); |
1250 | 1251 | interface->RemoveAddresses(); |
1251 | 1252 | |
1252 | | MutexLocker locker(sLock); |
| 1253 | RecursiveLocker locker(sLock); |
1253 | 1254 | sInterfaces.Remove(interface); |
1254 | 1255 | locker.Unlock(); |
1255 | 1256 | |
… |
… |
remove_interface(Interface* interface)
|
1265 | 1266 | void |
1266 | 1267 | interface_removed_device_interface(net_device_interface* deviceInterface) |
1267 | 1268 | { |
1268 | | MutexLocker locker(sLock); |
| 1269 | RecursiveLocker locker(sLock); |
1269 | 1270 | |
1270 | 1271 | Interface* interface = find_interface(deviceInterface->device->name); |
1271 | 1272 | if (interface != NULL) |
… |
… |
update_interface_address(InterfaceAddress* interfaceAddress, int32 option,
|
1396 | 1397 | Interface* |
1397 | 1398 | get_interface(net_domain* domain, uint32 index) |
1398 | 1399 | { |
1399 | | MutexLocker locker(sLock); |
| 1400 | RecursiveLocker locker(sLock); |
1400 | 1401 | |
1401 | 1402 | Interface* interface; |
1402 | 1403 | if (index == 0) |
… |
… |
get_interface(net_domain* domain, uint32 index)
|
1417 | 1418 | Interface* |
1418 | 1419 | get_interface(net_domain* domain, const char* name) |
1419 | 1420 | { |
1420 | | MutexLocker locker(sLock); |
| 1421 | RecursiveLocker locker(sLock); |
1421 | 1422 | |
1422 | 1423 | Interface* interface = find_interface(name); |
1423 | 1424 | if (interface == NULL) |
… |
… |
get_interface(net_domain* domain, const char* name)
|
1434 | 1435 | Interface* |
1435 | 1436 | get_interface_for_device(net_domain* domain, uint32 index) |
1436 | 1437 | { |
1437 | | MutexLocker locker(sLock); |
| 1438 | RecursiveLocker locker(sLock); |
1438 | 1439 | |
1439 | 1440 | InterfaceList::Iterator iterator = sInterfaces.GetIterator(); |
1440 | 1441 | while (Interface* interface = iterator.Next()) { |
… |
… |
get_interface_for_link(net_domain* domain, const sockaddr* _linkAddress)
|
1460 | 1461 | { |
1461 | 1462 | sockaddr_dl& linkAddress = *(sockaddr_dl*)_linkAddress; |
1462 | 1463 | |
1463 | | MutexLocker locker(sLock); |
| 1464 | RecursiveLocker locker(sLock); |
1464 | 1465 | |
1465 | 1466 | InterfaceList::Iterator iterator = sInterfaces.GetIterator(); |
1466 | 1467 | while (Interface* interface = iterator.Next()) { |
… |
… |
InterfaceAddress*
|
1506 | 1507 | get_interface_address_for_destination(net_domain* domain, |
1507 | 1508 | const sockaddr* destination) |
1508 | 1509 | { |
1509 | | MutexLocker locker(sLock); |
| 1510 | RecursiveLocker locker(sLock); |
1510 | 1511 | |
1511 | 1512 | InterfaceList::Iterator iterator = sInterfaces.GetIterator(); |
1512 | 1513 | while (Interface* interface = iterator.Next()) { |
… |
… |
get_interface_address_for_link(net_domain* domain, const sockaddr* address,
|
1533 | 1534 | { |
1534 | 1535 | sockaddr_dl& linkAddress = *(sockaddr_dl*)address; |
1535 | 1536 | |
1536 | | MutexLocker locker(sLock); |
| 1537 | RecursiveLocker locker(sLock); |
1537 | 1538 | |
1538 | 1539 | InterfaceList::Iterator iterator = sInterfaces.GetIterator(); |
1539 | 1540 | while (Interface* interface = iterator.Next()) { |
… |
… |
get_interface_address_for_link(net_domain* domain, const sockaddr* address,
|
1558 | 1559 | uint32 |
1559 | 1560 | count_interfaces() |
1560 | 1561 | { |
1561 | | MutexLocker locker(sLock); |
| 1562 | RecursiveLocker locker(sLock); |
1562 | 1563 | |
1563 | 1564 | return sInterfaces.Count(); |
1564 | 1565 | } |
… |
… |
count_interfaces()
|
1571 | 1572 | status_t |
1572 | 1573 | list_interfaces(int family, void* _buffer, size_t* bufferSize) |
1573 | 1574 | { |
1574 | | MutexLocker locker(sLock); |
| 1575 | RecursiveLocker locker(sLock); |
1575 | 1576 | |
1576 | 1577 | UserBuffer buffer(_buffer, *bufferSize); |
1577 | 1578 | |
… |
… |
list_interfaces(int family, void* _buffer, size_t* bufferSize)
|
1619 | 1620 | status_t |
1620 | 1621 | init_interfaces() |
1621 | 1622 | { |
1622 | | mutex_init(&sLock, "net interfaces"); |
| 1623 | recursive_lock_init(&sLock, "net interfaces"); |
1623 | 1624 | mutex_init(&sHashLock, "net local addresses"); |
1624 | 1625 | |
1625 | 1626 | new (&sInterfaces) InterfaceList; |
… |
… |
uninit_interfaces()
|
1650 | 1651 | remove_debugger_command("net_route", &dump_route); |
1651 | 1652 | #endif |
1652 | 1653 | |
1653 | | mutex_destroy(&sLock); |
| 1654 | recursive_lock_destroy(&sLock); |
1654 | 1655 | mutex_destroy(&sHashLock); |
1655 | 1656 | return B_OK; |
1656 | 1657 | } |