summaryrefslogtreecommitdiffstats
path: root/src/kern_wg.c
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 02:46:59 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 02:46:59 +0100
commit0a5977e6b12d5c6b9f19812d5e860c5f9eab4de4 (patch)
tree21aacd4bbc1ca31effd12c46441f0d048f3d69ce /src/kern_wg.c
parentBugfixes (diff)
downloadwireguard-openbsd-0a5977e6b12d5c6b9f19812d5e860c5f9eab4de4.tar.xz
wireguard-openbsd-0a5977e6b12d5c6b9f19812d5e860c5f9eab4de4.zip
Remove refcnt from fixedmap
Diffstat (limited to 'src/kern_wg.c')
-rw-r--r--src/kern_wg.c38
1 files changed, 2 insertions, 36 deletions
diff --git a/src/kern_wg.c b/src/kern_wg.c
index 63eb6a3fc40..8d3296fd3db 100644
--- a/src/kern_wg.c
+++ b/src/kern_wg.c
@@ -168,7 +168,6 @@ void
fm_init(struct fixed_map *fm)
{
bzero(fm, sizeof(*fm));
- rw_init(&fm->lock, "fixedmap");
fm_resize(fm, 128);
}
@@ -179,8 +178,6 @@ fm_resize(struct fixed_map *fm, size_t size)
size_t osize;
struct map_item *omap;
- /* No lock as fm_resize is only called in fm_init (no lock) or
- * fm_insert (already locked) */
osize = fm->size;
omap = fm->map;
@@ -198,10 +195,6 @@ fm_resize(struct fixed_map *fm, size_t size)
void
fm_destroy(struct fixed_map *fm)
{
- struct map_item *item;
- /* No lock, as this is the last reference */
- FM_FOREACH_FILLED(item, fm)
- refcnt_finalize(&item->cnt, "fm_wait");
free(fm->map, M_DEVBUF, 0);
}
@@ -210,7 +203,6 @@ fm_insert(struct fixed_map *fm, void *v)
{
struct map_item *item = NULL, *iter;
- rw_enter_write(&fm->lock);
retry:
FM_FOREACH_EMPTY(iter, fm) {
item = iter;
@@ -226,39 +218,19 @@ retry:
item->key = (arc4random() & ~(fm->size - 1)) + (item - fm->map);
item->state = FM_ITEM_FILLED;
item->value = v;
- refcnt_init(&item->cnt);
-
- rw_exit_write(&fm->lock);
return item->key;
}
-void
-fm_put(struct fixed_map *fm, uint32_t k)
-{
- struct map_item *item;
-
- rw_enter_read(&fm->lock);
- item = fm->map + (k & (fm->size - 1));
- if (item->key != k)
- panic("unexpected key, should exist");
- refcnt_rele_wake(&item->cnt);
- rw_exit_read(&fm->lock);
-}
-
void *
-fm_ref(struct fixed_map *fm, uint32_t k)
+fm_lookup(struct fixed_map *fm, uint32_t k)
{
void *v = NULL;
struct map_item *item;
- rw_enter_read(&fm->lock);
item = fm->map + (k & (fm->size - 1));
- if (item->key == k) {
+ if (item->key == k)
v = item->value;
- refcnt_take(&item->cnt);
- }
- rw_exit_read(&fm->lock);
return v;
}
@@ -267,17 +239,11 @@ fm_remove(struct fixed_map *fm, uint32_t k)
{
struct map_item *item;
- rw_enter_read(&fm->lock);
item = fm->map + (k & (fm->size - 1));
- refcnt_finalize(&item->cnt, "fm_wait");
- rw_exit_read(&fm->lock);
-
- rw_enter_write(&fm->lock);
if (item->key == k) {
item->state = FM_ITEM_EMPTY;
item->value = NULL;
}
- rw_exit_write(&fm->lock);
}
/*