#include <stdbool.h>
#include <stdlib.h>
+#include "ovs-atomic.h"
#include "util.h"
#ifdef __cplusplus
/* Adjusting capacity. */
void hmap_expand_at(struct hmap *, const char *where);
-#define hmap_expand(HMAP) hmap_expand_at(HMAP, SOURCE_LOCATOR)
+#define hmap_expand(HMAP) hmap_expand_at(HMAP, OVS_SOURCE_LOCATOR)
void hmap_shrink_at(struct hmap *, const char *where);
-#define hmap_shrink(HMAP) hmap_shrink_at(HMAP, SOURCE_LOCATOR)
+#define hmap_shrink(HMAP) hmap_shrink_at(HMAP, OVS_SOURCE_LOCATOR)
void hmap_reserve_at(struct hmap *, size_t capacity, const char *where);
#define hmap_reserve(HMAP, CAPACITY) \
- hmap_reserve_at(HMAP, CAPACITY, SOURCE_LOCATOR)
+ hmap_reserve_at(HMAP, CAPACITY, OVS_SOURCE_LOCATOR)
/* Insertion and deletion. */
static inline void hmap_insert_at(struct hmap *, struct hmap_node *,
size_t hash, const char *where);
#define hmap_insert(HMAP, NODE, HASH) \
- hmap_insert_at(HMAP, NODE, HASH, SOURCE_LOCATOR)
+ hmap_insert_at(HMAP, NODE, HASH, OVS_SOURCE_LOCATOR)
static inline void hmap_insert_fast(struct hmap *,
struct hmap_node *, size_t hash);
* HASH is only evaluated once.
*/
#define HMAP_FOR_EACH_WITH_HASH(NODE, MEMBER, HASH, HMAP) \
- for (ASSIGN_CONTAINER(NODE, hmap_first_with_hash(HMAP, HASH), MEMBER); \
+ for (INIT_CONTAINER(NODE, hmap_first_with_hash(HMAP, HASH), MEMBER); \
NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER); \
ASSIGN_CONTAINER(NODE, hmap_next_with_hash(&(NODE)->MEMBER), \
MEMBER))
#define HMAP_FOR_EACH_IN_BUCKET(NODE, MEMBER, HASH, HMAP) \
- for (ASSIGN_CONTAINER(NODE, hmap_first_in_bucket(HMAP, HASH), MEMBER); \
+ for (INIT_CONTAINER(NODE, hmap_first_in_bucket(HMAP, HASH), MEMBER); \
NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER); \
ASSIGN_CONTAINER(NODE, hmap_next_in_bucket(&(NODE)->MEMBER), MEMBER))
/* Iterates through every node in HMAP. */
#define HMAP_FOR_EACH(NODE, MEMBER, HMAP) \
- for (ASSIGN_CONTAINER(NODE, hmap_first(HMAP), MEMBER); \
+ for (INIT_CONTAINER(NODE, hmap_first(HMAP), MEMBER); \
NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER); \
ASSIGN_CONTAINER(NODE, hmap_next(HMAP, &(NODE)->MEMBER), MEMBER))
/* Safe when NODE may be freed (not needed when NODE may be removed from the
* hash map but its members remain accessible and intact). */
#define HMAP_FOR_EACH_SAFE(NODE, NEXT, MEMBER, HMAP) \
- for (ASSIGN_CONTAINER(NODE, hmap_first(HMAP), MEMBER); \
+ for (INIT_CONTAINER(NODE, hmap_first(HMAP), MEMBER); \
(NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER) \
- ? ASSIGN_CONTAINER(NEXT, hmap_next(HMAP, &(NODE)->MEMBER), MEMBER), 1 \
+ ? INIT_CONTAINER(NEXT, hmap_next(HMAP, &(NODE)->MEMBER), MEMBER), 1 \
: 0); \
(NODE) = (NEXT))
}
/* 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)
{