aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-05-20 17:33:20 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-05-20 18:02:25 -0600
commit541d1247c144afaf5837ab271219b9ab44d71d50 (patch)
tree9f8250be9054e2d7b23beb980297c432ceb8dcf7
parentUse codel limits for ooo counter (diff)
downloadwireguard-openbsd-541d1247c144afaf5837ab271219b9ab44d71d50.tar.xz
wireguard-openbsd-541d1247c144afaf5837ab271219b9ab44d71d50.zip
Use atomic counter operation when available
-rw-r--r--src/wg_noise.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/wg_noise.c b/src/wg_noise.c
index 36f3ec7..cdc56d1 100644
--- a/src/wg_noise.c
+++ b/src/wg_noise.c
@@ -18,7 +18,7 @@
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/param.h>
-
+#include <sys/atomic.h>
#include <sys/rwlock.h>
#include <crypto/wg_noise.h>
@@ -729,11 +729,15 @@ noise_remote_handshake_index_drop(struct noise_remote *r)
static uint64_t
noise_counter_send(struct noise_counter *ctr)
{
+#ifdef __LP64__
+ return atomic_inc_long_nv((u_long *)&ctr->c_send) - 1;
+#else
uint64_t ret;
rw_enter_write(&ctr->c_lock);
ret = ctr->c_send++;
rw_exit_write(&ctr->c_lock);
return ret;
+#endif
}
static int