2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 22:35:15 +00:00

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.
This commit is contained in:
Ben Pfaff
2011-03-25 15:26:30 -07:00
parent f391294fde
commit b3c01ed330
7 changed files with 109 additions and 116 deletions

View File

@@ -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);
}
}