X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fofp-msgs.c;h=d136f73d47cefd457a249d2c0a21d360d3178db3;hb=b0fb94a346e52f36aeef238dd5f9bef9a10c14ef;hp=af4178eb4867b843561c0aa70aa4fce45ad55ed3;hpb=67680b012be30d9c26eab999b83b08c6eb32dbd2;p=sliver-openvswitch.git diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c index af4178eb4..d136f73d4 100644 --- a/lib/ofp-msgs.c +++ b/lib/ofp-msgs.c @@ -23,6 +23,7 @@ #include "ofpbuf.h" #include "openflow/nicira-ext.h" #include "openflow/openflow.h" +#include "ovs-thread.h" #include "vlog.h" VLOG_DEFINE_THIS_MODULE(ofp_msgs); @@ -109,8 +110,11 @@ static enum ofperr ofpraw_from_ofphdrs(enum ofpraw *, const struct ofphdrs *); static ovs_be32 alloc_xid(void) { - static uint32_t next_xid = 1; - return htonl(next_xid++); + static atomic_uint32_t next_xid = ATOMIC_VAR_INIT(1); + uint32_t xid; + + atomic_add(&next_xid, 1, &xid); + return htonl(xid); } static uint32_t @@ -988,9 +992,10 @@ ofpraw_from_ofphdrs(enum ofpraw *raw, const struct ofphdrs *hdrs) static void ofpmsgs_init(void) { + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; const struct raw_info *info; - if (raw_instance_map.buckets) { + if (!ovsthread_once_start(&once)) { return; } @@ -1008,4 +1013,6 @@ ofpmsgs_init(void) ofphdrs_hash(&inst->hdrs)); } } + + ovsthread_once_done(&once); }