ofp-msgs: Make alloc_xid() thread-safe.
[sliver-openvswitch.git] / 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;
-    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