ofp-msgs: Make alloc_xid() thread-safe.
authorBen Pfaff <blp@nicira.com>
Fri, 26 Apr 2013 20:07:33 +0000 (13:07 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 23 Jul 2013 18:38:14 +0000 (11:38 -0700)
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
lib/ofp-msgs.c

index 5e043d2..8bb1754 100644 (file)
@@ -111,7 +111,14 @@ static ovs_be32
 alloc_xid(void)
 {
     static uint32_t next_xid = 1;
 alloc_xid(void)
 {
     static uint32_t next_xid = 1;
-    return htonl(next_xid++);
+    static pthread_mutex_t mutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER;
+    uint32_t xid;
+
+    xpthread_mutex_lock(&mutex);
+    xid = next_xid++;
+    xpthread_mutex_unlock(&mutex);
+
+    return htonl(xid);
 }
 \f
 static uint32_t
 }
 \f
 static uint32_t