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

« back to all changes in this revision

Viewing changes to lib/ovsdb-types.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:
1
 
/* Copyright (c) 2009, 2010, 2011 Nicira, Inc.
 
1
/* Copyright (c) 2009, 2010, 2011, 2013 Nicira, Inc.
2
2
 *
3
3
 * Licensed under the Apache License, Version 2.0 (the "License");
4
4
 * you may not use this file except in compliance with the License.
22
22
 
23
23
#include "dynamic-string.h"
24
24
#include "json.h"
 
25
#include "ovs-thread.h"
25
26
#include "ovsdb-data.h"
26
27
#include "ovsdb-error.h"
27
28
#include "ovsdb-parser.h"
158
159
const struct ovsdb_type *
159
160
ovsdb_base_type_get_enum_type(enum ovsdb_atomic_type atomic_type)
160
161
{
 
162
    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
161
163
    static struct ovsdb_type *types[OVSDB_N_TYPES];
162
164
 
163
 
    if (!types[atomic_type]) {
164
 
        struct ovsdb_type *type;
165
 
 
166
 
        types[atomic_type] = type = xmalloc(sizeof *type);
167
 
        ovsdb_base_type_init(&type->key, atomic_type);
168
 
        ovsdb_base_type_init(&type->value, OVSDB_TYPE_VOID);
169
 
        type->n_min = 1;
170
 
        type->n_max = UINT_MAX;
 
165
    if (ovsthread_once_start(&once)) {
 
166
        enum ovsdb_atomic_type i;
 
167
 
 
168
        for (i = 0; i < OVSDB_N_TYPES; i++) {
 
169
            struct ovsdb_type *type;
 
170
 
 
171
            types[i] = type = xmalloc(sizeof *type);
 
172
            ovsdb_base_type_init(&type->key, i);
 
173
            ovsdb_base_type_init(&type->value, OVSDB_TYPE_VOID);
 
174
            type->n_min = 1;
 
175
            type->n_max = UINT_MAX;
 
176
        }
 
177
 
 
178
        ovsthread_once_done(&once);
171
179
    }
172
180
    return types[atomic_type];
173
181
}