diff options
author | Jarno Rajahalme <jrajahalme@nicira.com> | 2014-02-07 11:34:01 -0800 |
---|---|---|
committer | Jarno Rajahalme <jrajahalme@nicira.com> | 2014-02-12 13:58:47 -0800 |
commit | 7614e5d01c3b971c57d825111e412b1182cc04c8 (patch) | |
tree | dc6f5464c8b122e3f6038da6e119032c888eecf4 /lib/hmap.h | |
parent | fc24d64d27b745593fe9d5a6c73dfc6dd9da5983 (diff) | |
download | openvswitch-7614e5d01c3b971c57d825111e412b1182cc04c8.tar.gz |
ofproto: Lock for vlan splinters only if have them.
Reading the hmap count for determining if it is empty or not is thread
safe, so avoid locking when not necessary.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/hmap.h')
-rw-r--r-- | lib/hmap.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/hmap.h b/lib/hmap.h index 76a73ac1a..445e74f0b 100644 --- a/lib/hmap.h +++ b/lib/hmap.h @@ -19,6 +19,7 @@ #include <stdbool.h> #include <stdlib.h> +#include "ovs-atomic.h" #include "util.h" #ifdef __cplusplus @@ -189,10 +190,13 @@ hmap_capacity(const struct hmap *hmap) } /* Returns true if 'hmap' currently contains no nodes, - * false otherwise. */ + * false otherwise. + * Note: While hmap in general is not thread-safe without additional locking, + * hmap_is_empty() is. */ static inline bool hmap_is_empty(const struct hmap *hmap) { + atomic_thread_fence(memory_order_acquire); return hmap->n == 0; } |