mirror of
https://github.com/openvswitch/ovs
synced 2025-10-25 15:07:05 +00:00
ovsdb-types: Make ovsdb_base_type_get_enum_type() thread-safe.
Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright (c) 2009, 2010, 2011 Nicira, Inc.
|
/* Copyright (c) 2009, 2010, 2011, 2013 Nicira, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "dynamic-string.h"
|
#include "dynamic-string.h"
|
||||||
#include "json.h"
|
#include "json.h"
|
||||||
|
#include "ovs-thread.h"
|
||||||
#include "ovsdb-data.h"
|
#include "ovsdb-data.h"
|
||||||
#include "ovsdb-error.h"
|
#include "ovsdb-error.h"
|
||||||
#include "ovsdb-parser.h"
|
#include "ovsdb-parser.h"
|
||||||
@@ -158,16 +159,23 @@ ovsdb_base_type_init(struct ovsdb_base_type *base, enum ovsdb_atomic_type type)
|
|||||||
const struct ovsdb_type *
|
const struct ovsdb_type *
|
||||||
ovsdb_base_type_get_enum_type(enum ovsdb_atomic_type atomic_type)
|
ovsdb_base_type_get_enum_type(enum ovsdb_atomic_type atomic_type)
|
||||||
{
|
{
|
||||||
|
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
|
||||||
static struct ovsdb_type *types[OVSDB_N_TYPES];
|
static struct ovsdb_type *types[OVSDB_N_TYPES];
|
||||||
|
|
||||||
if (!types[atomic_type]) {
|
if (ovsthread_once_start(&once)) {
|
||||||
struct ovsdb_type *type;
|
enum ovsdb_atomic_type i;
|
||||||
|
|
||||||
types[atomic_type] = type = xmalloc(sizeof *type);
|
for (i = 0; i < OVSDB_N_TYPES; i++) {
|
||||||
ovsdb_base_type_init(&type->key, atomic_type);
|
struct ovsdb_type *type;
|
||||||
ovsdb_base_type_init(&type->value, OVSDB_TYPE_VOID);
|
|
||||||
type->n_min = 1;
|
types[i] = type = xmalloc(sizeof *type);
|
||||||
type->n_max = UINT_MAX;
|
ovsdb_base_type_init(&type->key, i);
|
||||||
|
ovsdb_base_type_init(&type->value, OVSDB_TYPE_VOID);
|
||||||
|
type->n_min = 1;
|
||||||
|
type->n_max = UINT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
ovsthread_once_done(&once);
|
||||||
}
|
}
|
||||||
return types[atomic_type];
|
return types[atomic_type];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user