aboutsummaryrefslogtreecommitdiff
path: root/lib/netdev-linux.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2013-04-29 14:34:48 -0700
committerBen Pfaff <blp@nicira.com>2013-05-03 13:29:47 -0700
commit559eb2308b4d616590aba34bb8f4dd7f12ae4587 (patch)
treeed978748f54c2a8c1296cfd1b0e7ede98a0f7eb5 /lib/netdev-linux.c
parente37726e467cf5523161c1b932b979a8818c76b25 (diff)
netdev-linux: Mark more static data as "const".
This makes this code more obviously thread-safe. Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/netdev-linux.c')
-rw-r--r--lib/netdev-linux.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index c0e0c40c..722b88be 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -139,6 +139,8 @@ struct tc {
* Written only by TC implementation. */
};
+#define TC_INITIALIZER(TC, OPS) { OPS, HMAP_INITIALIZER(&(TC)->queues) }
+
/* One traffic control queue.
*
* Each TC implementation subclasses this with whatever additional data it
@@ -311,7 +313,7 @@ static const struct tc_ops tc_ops_hfsc;
static const struct tc_ops tc_ops_default;
static const struct tc_ops tc_ops_other;
-static const struct tc_ops *tcs[] = {
+static const struct tc_ops *const tcs[] = {
&tc_ops_htb, /* Hierarchy token bucket (see tc-htb(8)). */
&tc_ops_hfsc, /* Hierarchical fair service curve. */
&tc_ops_default, /* Default qdisc (see tc-pfifo_fast(8)). */
@@ -1851,7 +1853,7 @@ static int
netdev_linux_get_qos_types(const struct netdev *netdev OVS_UNUSED,
struct sset *types)
{
- const struct tc_ops **opsp;
+ const struct tc_ops *const *opsp;
for (opsp = tcs; *opsp != NULL; opsp++) {
const struct tc_ops *ops = *opsp;
@@ -1865,7 +1867,7 @@ netdev_linux_get_qos_types(const struct netdev *netdev OVS_UNUSED,
static const struct tc_ops *
tc_lookup_ovs_name(const char *name)
{
- const struct tc_ops **opsp;
+ const struct tc_ops *const *opsp;
for (opsp = tcs; *opsp != NULL; opsp++) {
const struct tc_ops *ops = *opsp;
@@ -1879,7 +1881,7 @@ tc_lookup_ovs_name(const char *name)
static const struct tc_ops *
tc_lookup_linux_name(const char *name)
{
- const struct tc_ops **opsp;
+ const struct tc_ops *const *opsp;
for (opsp = tcs; *opsp != NULL; opsp++) {
const struct tc_ops *ops = *opsp;
@@ -3559,13 +3561,11 @@ default_install__(struct netdev *netdev)
{
struct netdev_dev_linux *netdev_dev =
netdev_dev_linux_cast(netdev_get_dev(netdev));
- static struct tc *tc;
+ static const struct tc tc = TC_INITIALIZER(&tc, &tc_ops_default);
- if (!tc) {
- tc = xmalloc(sizeof *tc);
- tc_init(tc, &tc_ops_default);
- }
- netdev_dev->tc = tc;
+ /* Nothing but a tc class implementation is allowed to write to a tc. This
+ * class never does that, so we can legitimately use a const tc object. */
+ netdev_dev->tc = CONST_CAST(struct tc *, &tc);
}
static int
@@ -3608,13 +3608,11 @@ other_tc_load(struct netdev *netdev, struct ofpbuf *nlmsg OVS_UNUSED)
{
struct netdev_dev_linux *netdev_dev =
netdev_dev_linux_cast(netdev_get_dev(netdev));
- static struct tc *tc;
+ static const struct tc tc = TC_INITIALIZER(&tc, &tc_ops_other);
- if (!tc) {
- tc = xmalloc(sizeof *tc);
- tc_init(tc, &tc_ops_other);
- }
- netdev_dev->tc = tc;
+ /* Nothing but a tc class implementation is allowed to write to a tc. This
+ * class never does that, so we can legitimately use a const tc object. */
+ netdev_dev->tc = CONST_CAST(struct tc *, &tc);
return 0;
}