summaryrefslogtreecommitdiffstats
path: root/src/fixedmap.h
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-28 21:50:20 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-30 22:56:35 +0100
commit10d253dadaca40fd8b2abce4dc8e5565b46e2510 (patch)
treec54c0857b0feca96a5373c82e44a77ff2470f209 /src/fixedmap.h
parentAdd more verbose messages (diff)
downloadwireguard-openbsd-10d253dadaca40fd8b2abce4dc8e5565b46e2510.tar.xz
wireguard-openbsd-10d253dadaca40fd8b2abce4dc8e5565b46e2510.zip
Big re-work of wireguard.c
Diffstat (limited to 'src/fixedmap.h')
-rw-r--r--src/fixedmap.h28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/fixedmap.h b/src/fixedmap.h
index 0226fd67ffa..dad4d596fdd 100644
--- a/src/fixedmap.h
+++ b/src/fixedmap.h
@@ -18,29 +18,33 @@
#define __FIXEDMAP_H__
#include <sys/types.h>
-#include <sys/rwlock.h>
+#include <sys/refcnt.h>
+
+#define FM_FOREACH(item, fm) \
+ for (item = (fm)->map; item < (fm)->map + (fm)->size; item++)
+#define FM_FOREACH_FILLED(item, fm) \
+ FM_FOREACH(item, fm) if (item->state == FM_ITEM_FILLED)
+#define FM_FOREACH_EMPTY(item, fm) \
+ FM_FOREACH(item, fm) if (item->state == FM_ITEM_EMPTY)
struct fixed_map {
- struct rwlock lock;
- uint8_t bits;
+ size_t size;
struct map_item {
enum {
FM_ITEM_EMPTY = 0,
- FM_ITEM_RESERVED,
FM_ITEM_FILLED,
- } state;
- uint32_t key;
- void *value;
- } *map;
+ } state;
+ uint32_t key;
+ struct refcnt cnt;
+ void *value;
+ } *map;
};
void fm_init(struct fixed_map *);
void fm_destroy(struct fixed_map *);
-void fm_resize(struct fixed_map *, size_t);
-uint32_t fm_reserve(struct fixed_map *);
-void fm_set(struct fixed_map *, uint32_t, void *);
uint32_t fm_insert(struct fixed_map *, void *);
-void *fm_lookup(struct fixed_map *, uint32_t);
+void *fm_ref(struct fixed_map *, uint32_t);
+void fm_put(struct fixed_map *, uint32_t);
void fm_remove(struct fixed_map *, uint32_t);
#endif /* __FIXEDMAP_H__ */