[PATCH 05/12] index: NewIndex(): don't use separate read-lock to check if index is present
Simon Ruderich
simon at ruderich.org
Mon Jan 1 11:52:55 CET 2018
The new index is random making collisions very unlikely, therefore
taking a separate read-only lock before taking the full lock in most
cases anyway will not improve performance and only makes the code more
complicated. However I didn't benchmark this change.
---
src/index.go | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/src/index.go b/src/index.go
index 13e8693..bf8f0a0 100644
--- a/src/index.go
+++ b/src/index.go
@@ -63,21 +63,15 @@ func (table *IndexTable) NewIndex(peer *Peer) (uint32, error) {
// check if index used
- table.mutex.RLock()
- _, ok := table.table[index]
- table.mutex.RUnlock()
- if ok {
- continue
- }
-
- // map index to handshake
-
table.mutex.Lock()
_, found := table.table[index]
if found {
table.mutex.Unlock()
continue
}
+
+ // map index to handshake
+
table.table[index] = IndexTableEntry{
peer: peer,
handshake: &peer.handshake,
--
2.15.1
More information about the WireGuard
mailing list