aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-03-25 15:26:30 -0700
committerBen Pfaff <blp@nicira.com>2011-03-31 16:42:01 -0700
commitb3c01ed3308e7899e98e981bf465f74be86f5f12 (patch)
tree20103c6515c654382cc9b43ae0058b7393a0defb /lib
parentf391294fde05ecae7c9a1ff8752f872a1db94f3a (diff)
Convert shash users that don't use the 'data' value to sset instead.
In each of the cases converted here, an shash was used simply to maintain a set of strings, with the shash_nodes' 'data' values set to NULL. This commit converts them to use sset instead.
Diffstat (limited to 'lib')
-rw-r--r--lib/dpif-linux.c18
-rw-r--r--lib/fatal-signal.c24
-rw-r--r--lib/netdev.c21
3 files changed, 28 insertions, 35 deletions
diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c
index 509174c8..3c22b556 100644
--- a/lib/dpif-linux.c
+++ b/lib/dpif-linux.c
@@ -45,6 +45,7 @@
#include "rtnetlink.h"
#include "rtnetlink-link.h"
#include "shash.h"
+#include "sset.h"
#include "svec.h"
#include "unaligned.h"
#include "util.h"
@@ -125,7 +126,7 @@ struct dpif_linux {
unsigned int listen_mask;
/* Change notification. */
- struct shash changed_ports; /* Ports that have changed. */
+ struct sset changed_ports; /* Ports that have changed. */
struct rtnetlink_notifier port_notifier;
bool change_error;
};
@@ -231,7 +232,7 @@ open_dpif(const struct dpif_linux_dp *dp, struct dpif **dpifp)
}
dpif->listen_mask = 0;
dpif->dp_ifindex = dp->dp_ifindex;
- shash_init(&dpif->changed_ports);
+ sset_init(&dpif->changed_ports);
dpif->change_error = false;
*dpifp = &dpif->dpif;
@@ -247,7 +248,7 @@ dpif_linux_close(struct dpif *dpif_)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
rtnetlink_link_notifier_unregister(&dpif->port_notifier);
- shash_destroy(&dpif->changed_ports);
+ sset_destroy(&dpif->changed_ports);
free(dpif);
}
@@ -483,11 +484,10 @@ dpif_linux_port_poll(const struct dpif *dpif_, char **devnamep)
if (dpif->change_error) {
dpif->change_error = false;
- shash_clear(&dpif->changed_ports);
+ sset_clear(&dpif->changed_ports);
return ENOBUFS;
- } else if (!shash_is_empty(&dpif->changed_ports)) {
- struct shash_node *node = shash_first(&dpif->changed_ports);
- *devnamep = shash_steal(&dpif->changed_ports, node);
+ } else if (!sset_is_empty(&dpif->changed_ports)) {
+ *devnamep = sset_pop(&dpif->changed_ports);
return 0;
} else {
return EAGAIN;
@@ -498,7 +498,7 @@ static void
dpif_linux_port_poll_wait(const struct dpif *dpif_)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- if (!shash_is_empty(&dpif->changed_ports) || dpif->change_error) {
+ if (!sset_is_empty(&dpif->changed_ports) || dpif->change_error) {
poll_immediate_wake();
} else {
rtnetlink_link_notifier_wait();
@@ -1041,7 +1041,7 @@ dpif_linux_port_changed(const struct rtnetlink_link_change *change,
{
/* Our datapath changed, either adding a new port or deleting an
* existing one. */
- shash_add_once(&dpif->changed_ports, change->ifname, NULL);
+ sset_add(&dpif->changed_ports, change->ifname);
}
} else {
dpif->change_error = true;
diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c
index 81f8f284..ed82173a 100644
--- a/lib/fatal-signal.c
+++ b/lib/fatal-signal.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2009, 2010 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
#include <unistd.h>
#include "poll-loop.h"
#include "shash.h"
+#include "sset.h"
#include "socket-util.h"
#include "util.h"
#include "vlog.h"
@@ -194,8 +195,8 @@ call_hooks(int sig_nr)
}
}
-/* Files to delete on exit. (The 'data' member of each node is unused.) */
-static struct shash files = SHASH_INITIALIZER(&files);
+/* Files to delete on exit. */
+static struct sset files = SSET_INITIALIZER(&files);
/* Has a hook function been registered with fatal_signal_add_hook() (and not
* cleared by fatal_signal_fork())? */
@@ -215,7 +216,7 @@ fatal_signal_add_file_to_unlink(const char *file)
fatal_signal_add_hook(unlink_files, cancel_files, NULL, true);
}
- shash_add_once(&files, file, NULL);
+ sset_add(&files, file);
}
/* Unregisters 'file' from being unlinked when the program terminates via
@@ -223,12 +224,7 @@ fatal_signal_add_file_to_unlink(const char *file)
void
fatal_signal_remove_file_to_unlink(const char *file)
{
- struct shash_node *node;
-
- node = shash_find(&files, file);
- if (node) {
- shash_delete(&files, node);
- }
+ sset_find_and_delete(&files, file);
}
/* Like fatal_signal_remove_file_to_unlink(), but also unlinks 'file'.
@@ -255,17 +251,17 @@ unlink_files(void *aux OVS_UNUSED)
static void
cancel_files(void *aux OVS_UNUSED)
{
- shash_clear(&files);
+ sset_clear(&files);
added_hook = false;
}
static void
do_unlink_files(void)
{
- struct shash_node *node;
+ const char *file;
- SHASH_FOR_EACH (node, &files) {
- unlink(node->name);
+ SSET_FOR_EACH (file, &files) {
+ unlink(file);
}
}
diff --git a/lib/netdev.c b/lib/netdev.c
index f06742ae..4254c1ad 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -37,6 +37,7 @@
#include "packets.h"
#include "poll-loop.h"
#include "shash.h"
+#include "sset.h"
#include "svec.h"
#include "vlog.h"
@@ -1444,7 +1445,7 @@ netdev_notifier_init(struct netdev_notifier *notifier, struct netdev *netdev,
/* Tracks changes in the status of a set of network devices. */
struct netdev_monitor {
struct shash polled_netdevs;
- struct shash changed_netdevs;
+ struct sset changed_netdevs;
};
/* Creates and returns a new structure for monitor changes in the status of
@@ -1454,7 +1455,7 @@ netdev_monitor_create(void)
{
struct netdev_monitor *monitor = xmalloc(sizeof *monitor);
shash_init(&monitor->polled_netdevs);
- shash_init(&monitor->changed_netdevs);
+ sset_init(&monitor->changed_netdevs);
return monitor;
}
@@ -1472,7 +1473,7 @@ netdev_monitor_destroy(struct netdev_monitor *monitor)
}
shash_destroy(&monitor->polled_netdevs);
- shash_destroy(&monitor->changed_netdevs);
+ sset_destroy(&monitor->changed_netdevs);
free(monitor);
}
}
@@ -1482,7 +1483,7 @@ netdev_monitor_cb(struct netdev_notifier *notifier)
{
struct netdev_monitor *monitor = notifier->aux;
const char *name = netdev_get_name(notifier->netdev);
- shash_add_once(&monitor->changed_netdevs, name, NULL);
+ sset_add(&monitor->changed_netdevs, name);
}
/* Attempts to add 'netdev' as a netdev monitored by 'monitor'. Returns 0 if
@@ -1526,10 +1527,7 @@ netdev_monitor_remove(struct netdev_monitor *monitor, struct netdev *netdev)
shash_delete(&monitor->polled_netdevs, node);
/* Drop any pending notification. */
- node = shash_find(&monitor->changed_netdevs, netdev_name);
- if (node) {
- shash_delete(&monitor->changed_netdevs, node);
- }
+ sset_find_and_delete(&monitor->changed_netdevs, netdev_name);
}
}
@@ -1543,12 +1541,11 @@ netdev_monitor_remove(struct netdev_monitor *monitor, struct netdev *netdev)
int
netdev_monitor_poll(struct netdev_monitor *monitor, char **devnamep)
{
- struct shash_node *node = shash_first(&monitor->changed_netdevs);
- if (!node) {
+ if (sset_is_empty(&monitor->changed_netdevs)) {
*devnamep = NULL;
return EAGAIN;
} else {
- *devnamep = shash_steal(&monitor->changed_netdevs, node);
+ *devnamep = sset_pop(&monitor->changed_netdevs);
return 0;
}
}
@@ -1559,7 +1556,7 @@ netdev_monitor_poll(struct netdev_monitor *monitor, char **devnamep)
void
netdev_monitor_poll_wait(const struct netdev_monitor *monitor)
{
- if (!shash_is_empty(&monitor->changed_netdevs)) {
+ if (!sset_is_empty(&monitor->changed_netdevs)) {
poll_immediate_wake();
} else {
/* XXX Nothing needed here for netdev_linux, but maybe other netdev