mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 06:39:01 +08:00
Networking: The network device list was protected by a re-entrant semaphore. With the recent change to support network device callback, the network stack needs to access the network device list too. Some drivers, however, run the network stack from the interrupt level -- this is bad but a fact in the current state. Of course,those drivers are unable to take the semaphore and will assert.
The solution here is to eliminate the device devices semaphore altogether. This eliminates netdev_semtake() and netdev_semgive() and replaces them with net_lock() and net_unlock() which have larger scope as needed for this purpose.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/netdev/netdev_count.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -45,6 +45,7 @@
|
||||
|
||||
#include <nuttx/net/netdev.h>
|
||||
|
||||
#include "utils/utils.h"
|
||||
#include "netdev/netdev.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -91,11 +92,12 @@
|
||||
int netdev_count(void)
|
||||
{
|
||||
struct net_driver_s *dev;
|
||||
net_lock_t save;
|
||||
int ndev;
|
||||
|
||||
netdev_semtake();
|
||||
save = net_lock();
|
||||
for (dev = g_netdevices, ndev = 0; dev; dev = dev->flink, ndev++);
|
||||
netdev_semgive();
|
||||
net_unlock(save);
|
||||
return ndev;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user