lib/jsonrpc, lib/ofp-msgs, lib/ofp-parse: Use atomic_count.
authorJarno Rajahalme <jrajahalme@nicira.com>
Fri, 29 Aug 2014 17:34:52 +0000 (10:34 -0700)
committerJarno Rajahalme <jrajahalme@nicira.com>
Fri, 29 Aug 2014 17:34:52 +0000 (10:34 -0700)
Trivial ID counters do not synchronize anything, therefore can use
atomic_count.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/jsonrpc.c
lib/ofp-msgs.c
lib/ofp-parse.c

index 842d117..0841ad8 100644 (file)
@@ -516,10 +516,10 @@ jsonrpc_create(enum jsonrpc_msg_type type, const char *method,
 static struct json *
 jsonrpc_create_id(void)
 {
-    static atomic_uint next_id = ATOMIC_VAR_INIT(0);
+    static atomic_count next_id = ATOMIC_COUNT_INIT(0);
     unsigned int id;
 
-    atomic_add(&next_id, 1, &id);
+    id = atomic_count_inc(&next_id);
     return json_integer_create(id);
 }
 
index 3e93466..904aba6 100644 (file)
@@ -110,11 +110,9 @@ static enum ofperr ofpraw_from_ofphdrs(enum ofpraw *, const struct ofphdrs *);
 static ovs_be32
 alloc_xid(void)
 {
-    static atomic_uint32_t next_xid = ATOMIC_VAR_INIT(1);
-    uint32_t xid;
+    static atomic_count next_xid = ATOMIC_COUNT_INIT(1);
 
-    atomic_add(&next_xid, 1, &xid);
-    return htonl(xid);
+    return htonl(atomic_count_inc(&next_xid));
 }
 \f
 static uint32_t
index 9bafa8d..eed5a08 100644 (file)
@@ -730,11 +730,11 @@ parse_flow_monitor_request__(struct ofputil_flow_monitor_request *fmr,
                              const char *str_, char *string,
                              enum ofputil_protocol *usable_protocols)
 {
-    static atomic_uint32_t id = ATOMIC_VAR_INIT(0);
+    static atomic_count id = ATOMIC_COUNT_INIT(0);
     char *save_ptr = NULL;
     char *name;
 
-    atomic_add(&id, 1, &fmr->id);
+    fmr->id = atomic_count_inc(&id);
 
     fmr->flags = (NXFMF_INITIAL | NXFMF_ADD | NXFMF_DELETE | NXFMF_MODIFY
                   | NXFMF_OWN | NXFMF_ACTIONS);