Prepared net_device_monitor to accept device removal events.
- Introduced public net_device_monitor. - Changed the link protocol to maintain a lock per instance instead of inside the FIFO. Now all of the link instance data is protected. - Adapted the link protocol to use net_device_monitor. - Introduced a private Fifo class which doesn't maintain it's own lock. - Maybe we should add something like a public net_protocol_implementation which maintains a fifo and a benaphore? With the fifo using the structure's lock instead of maintaining it's own. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20614 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -593,9 +593,11 @@ unregister_device_handler(struct net_device *device, int32 type)
|
||||
|
||||
|
||||
status_t
|
||||
register_device_monitor(struct net_device *device,
|
||||
net_receive_func receiveFunc, void *cookie)
|
||||
register_device_monitor(net_device *device, net_device_monitor *monitor)
|
||||
{
|
||||
if (monitor->receive == NULL || monitor->event == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
|
||||
// find device interface for this device
|
||||
@@ -604,23 +606,13 @@ register_device_monitor(struct net_device *device,
|
||||
return ENODEV;
|
||||
|
||||
BenaphoreLocker _(interface->rx_lock);
|
||||
|
||||
// Add new monitor
|
||||
|
||||
net_device_monitor *monitor = new (std::nothrow) net_device_monitor;
|
||||
if (monitor == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
monitor->func = receiveFunc;
|
||||
monitor->cookie = cookie;
|
||||
interface->monitor_funcs.Add(monitor);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
unregister_device_monitor(struct net_device *device,
|
||||
net_receive_func receiveFunc, void *cookie)
|
||||
unregister_device_monitor(net_device *device, net_device_monitor *monitor)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
|
||||
@@ -635,12 +627,8 @@ unregister_device_monitor(struct net_device *device,
|
||||
|
||||
DeviceMonitorList::Iterator iterator = interface->monitor_funcs.GetIterator();
|
||||
while (iterator.HasNext()) {
|
||||
net_device_monitor *monitor = iterator.Next();
|
||||
|
||||
if (monitor->cookie == cookie && monitor->func == receiveFunc) {
|
||||
// found it
|
||||
if (iterator.Next() == monitor) {
|
||||
iterator.Remove();
|
||||
delete monitor;
|
||||
return B_OK;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user