X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fhmap.c;h=71943a74e6e092f5c2f2aba4fac1be4f52137b49;hb=c6278d208924bb04c41266ddca276712f95533bc;hp=ea08ab80e8633d53a116b9c5df0417f54f0c453d;hpb=064af42167bf4fc9aaea2702d80ce08074b889c0;p=openvswitch diff --git a/lib/hmap.c b/lib/hmap.c index ea08ab80..71943a74 100644 --- a/lib/hmap.c +++ b/lib/hmap.c @@ -1,17 +1,17 @@ /* - * Copyright (c) 2008, 2009 Nicira Networks. + * Copyright (c) 2008, 2009, 2010 Nicira Networks. * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -48,11 +48,17 @@ hmap_swap(struct hmap *a, struct hmap *b) struct hmap tmp = *a; *a = *b; *b = tmp; - if (a->buckets == &b->one) { - a->buckets = &a->one; - } - if (b->buckets == &a->one) { - b->buckets = &b->one; + hmap_moved(a); + hmap_moved(b); +} + +/* Adjusts 'hmap' to compensate for having moved position in memory (e.g. due + * to realloc()). */ +void +hmap_moved(struct hmap *hmap) +{ + if (!hmap->mask) { + hmap->buckets = &hmap->one; } } @@ -143,3 +149,17 @@ hmap_reserve(struct hmap *hmap, size_t n) resize(hmap, new_mask); } } + +/* Adjusts 'hmap' to compensate for 'old_node' having moved position in memory + * to 'node' (e.g. due to realloc()). */ +void +hmap_node_moved(struct hmap *hmap, + struct hmap_node *old_node, struct hmap_node *node) +{ + struct hmap_node **bucket = &hmap->buckets[node->hash & hmap->mask]; + while (*bucket != old_node) { + bucket = &(*bucket)->next; + } + *bucket = node; +} +