~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to lib/ofp-msgs.c

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include "ofpbuf.h"
24
24
#include "openflow/nicira-ext.h"
25
25
#include "openflow/openflow.h"
 
26
#include "ovs-thread.h"
26
27
#include "vlog.h"
27
28
 
28
29
VLOG_DEFINE_THIS_MODULE(ofp_msgs);
109
110
static ovs_be32
110
111
alloc_xid(void)
111
112
{
112
 
    static uint32_t next_xid = 1;
113
 
    return htonl(next_xid++);
 
113
    static atomic_uint32_t next_xid = ATOMIC_VAR_INIT(1);
 
114
    uint32_t xid;
 
115
 
 
116
    atomic_add(&next_xid, 1, &xid);
 
117
    return htonl(xid);
114
118
}
115
119
 
116
120
static uint32_t
320
324
    return ofpraw_pull(raw, &msg);
321
325
}
322
326
 
 
327
/* Does the same job as ofpraw_decode(), except that it assert-fails if
 
328
 * ofpraw_decode() would have reported an error.  Thus, it's able to use the
 
329
 * return value for the OFPRAW_* message type instead of an error code.
 
330
 *
 
331
 * (It only makes sense to use this function if you previously called
 
332
 * ofpraw_decode() on the message and thus know that it's OK.) */
 
333
enum ofpraw
 
334
ofpraw_decode_assert(const struct ofp_header *oh)
 
335
{
 
336
    enum ofperr error;
 
337
    enum ofpraw raw;
 
338
 
 
339
    error = ofpraw_decode(&raw, oh);
 
340
    ovs_assert(!error);
 
341
    return raw;
 
342
}
 
343
 
323
344
/* Determines the OFPRAW_* type of the OpenFlow message in 'msg', which starts
324
345
 * at 'msg->data' and has length 'msg->size' bytes.  On success, returns 0 and
325
346
 * stores the type into '*rawp'.  On failure, returns an OFPERR_* error code
403
424
}
404
425
 
405
426
/* Does the same job as ofpraw_pull(), except that it assert-fails if
406
 
 * ofpbuf_pull() would have reported an error.  Thus, it's able to use the
 
427
 * ofpraw_pull() would have reported an error.  Thus, it's able to use the
407
428
 * return value for the OFPRAW_* message type instead of an error code.
408
429
 *
409
430
 * (It only makes sense to use this function if you previously called
410
 
 * ofpbuf_decode() on the message and thus know that it's OK.) */
 
431
 * ofpraw_decode() on the message and thus know that it's OK.) */
411
432
enum ofpraw
412
433
ofpraw_pull_assert(struct ofpbuf *msg)
413
434
{
971
992
static void
972
993
ofpmsgs_init(void)
973
994
{
 
995
    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
974
996
    const struct raw_info *info;
975
997
 
976
 
    if (raw_instance_map.buckets) {
 
998
    if (!ovsthread_once_start(&once)) {
977
999
        return;
978
1000
    }
979
1001
 
991
1013
                        ofphdrs_hash(&inst->hdrs));
992
1014
        }
993
1015
    }
 
1016
 
 
1017
    ovsthread_once_done(&once);
994
1018
}