summaryrefslogtreecommitdiff
path: root/lib/jsonrpc.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2013-04-15 14:35:18 -0700
committerBen Pfaff <blp@nicira.com>2013-07-22 10:53:08 -0700
commitd7eea710a02193d6384174fa3f3e7d10d5248344 (patch)
tree9703ead11561ae64a996a808663e3cb7e09977d9 /lib/jsonrpc.c
parent06717cbd62f400c0596bd0bbcf0fc8fb03c7801c (diff)
downloadopenvswitch-d7eea710a02193d6384174fa3f3e7d10d5248344.tar.gz
jsonrpc: Make thread-safe.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/jsonrpc.c')
-rw-r--r--lib/jsonrpc.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index b4bbc8403..6c482c2d1 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -26,6 +26,7 @@
#include "json.h"
#include "list.h"
#include "ofpbuf.h"
+#include "ovs-thread.h"
#include "poll-loop.h"
#include "reconnect.h"
#include "stream.h"
@@ -514,8 +515,15 @@ jsonrpc_create(enum jsonrpc_msg_type type, const char *method,
static struct json *
jsonrpc_create_id(void)
{
- static unsigned int id;
- return json_integer_create(id++);
+ static pthread_mutex_t mutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER;
+ static unsigned int next_id;
+ unsigned int id;
+
+ xpthread_mutex_lock(&mutex);
+ id = next_id++;
+ xpthread_mutex_unlock(&mutex);
+
+ return json_integer_create(id);
}
struct jsonrpc_msg *