diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c index a940df81c..82473a177 100644 --- a/lib/netdev-dummy.c +++ b/lib/netdev-dummy.c @@ -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;