mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
netdev-dummy: Make counter thread-safe.
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
This commit is contained in:
@@ -241,8 +241,15 @@ static int
|
||||
netdev_dummy_create(const struct netdev_class *class, const char *name,
|
||||
struct netdev **netdevp)
|
||||
{
|
||||
static unsigned int n = 0xaa550000;
|
||||
static unsigned int next_n = 0xaa550000;
|
||||
static pthread_mutex_t mutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER;
|
||||
|
||||
struct netdev_dummy *netdev;
|
||||
unsigned int n;
|
||||
|
||||
xpthread_mutex_lock(&mutex);
|
||||
n = next_n++;
|
||||
xpthread_mutex_unlock(&mutex);
|
||||
|
||||
netdev = xzalloc(sizeof *netdev);
|
||||
netdev_init(&netdev->up, name, class);
|
||||
@@ -265,8 +272,6 @@ netdev_dummy_create(const struct netdev_class *class, const char *name,
|
||||
|
||||
shash_add(&dummy_netdevs, name, netdev);
|
||||
|
||||
n++;
|
||||
|
||||
*netdevp = &netdev->up;
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user