[ovs-dev] [threads 03/23] jsonrpc: Make thread-safe.
Alex Wang
alexw at nicira.com
Mon Jul 22 16:14:48 UTC 2013
Looks good to me,
On Thu, Jul 18, 2013 at 4:15 PM, Ben Pfaff <blp at nicira.com> wrote:
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
> lib/jsonrpc.c | 12 ++++++++++--
> 1 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
> index b4bbc84..6c482c2 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 *
> --
> 1.7.2.5
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20130722/1e03a00d/attachment-0003.html>
More information about the dev
mailing list