From d0c79f7fe0954b5d607e4190d26bb6b5ba75ceaf Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 26 Apr 2013 13:07:33 -0700 Subject: [PATCH] ofp-msgs: Make alloc_xid() thread-safe. Signed-off-by: Ben Pfaff Acked-by: Andy Zhou --- lib/ofp-msgs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c index 5e043d245..8bb1754f6 100644 --- a/lib/ofp-msgs.c +++ b/lib/ofp-msgs.c @@ -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); } static uint32_t -- 2.47.0