2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +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:
Ben Pfaff
2013-04-26 12:58:14 -07:00
parent 558103f071
commit 01cdb3a111

View File

@@ -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;