diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-10-25 16:54:09 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-10-31 17:25:23 +0100 |
commit | d4e27527f0d6960899798f159d2974e02e4532cb (patch) | |
tree | ff318af1d4d0d47c990d2809a3bd2970e694692c /src/peer.h | |
parent | compat: be sure to include header before testing (diff) | |
download | wireguard-monolithic-historical-d4e27527f0d6960899798f159d2974e02e4532cb.tar.xz wireguard-monolithic-historical-d4e27527f0d6960899798f159d2974e02e4532cb.zip |
peer: get rid of peer_for_each magic
Since the peer list is protected by the device_update_lock, and since
items are removed from the peer list before putting their final
reference, we don't actually need to take a reference when iterating.
This allows us to simplify the macro considerably.
Suggested-by: Johannes Berg <johannes@sipsolutions.net>
Diffstat (limited to 'src/peer.h')
-rw-r--r-- | src/peer.h | 30 |
1 files changed, 0 insertions, 30 deletions
@@ -69,34 +69,4 @@ struct wireguard_peer *peer_lookup_by_index(struct wireguard_device *wg, u32 ind unsigned int peer_total_count(struct wireguard_device *wg); -/* This is a macro iterator of essentially as follows, with the - * exception that typing `break` in the ITERATOR_BODY will still - * actually put the peer reference: - * - * if (__should_lock) - * mutex_lock(&(__wg)->device_update_lock); - * else - * lockdep_assert_held(&(__wg)->device_update_lock) - * list_for_each_entry_safe (__peer, __temp, &(__wg)->peer_list, peer_list) { - * __peer = peer_rcu_get(__peer); - * if (!__peer) - * continue; - * ITERATOR_BODY - * peer_put(__peer); - * } - * if (__should_lock) - * mutex_unlock(&(__wg)->device_update_lock); - * - * While it's really ugly to look at, the code gcc produces from it is actually perfect. - */ -#define pfe_label(n) __PASTE(__PASTE(pfe_label_, n ## _), __LINE__) -#define peer_for_each(__wg, __peer, __temp, __should_lock) \ - if (1) { if (__should_lock) mutex_lock(&(__wg)->device_update_lock); else lockdep_assert_held(&(__wg)->device_update_lock); goto pfe_label(1); } else pfe_label(1): \ - if (1) goto pfe_label(2); else while (1) if (1) { if (__should_lock) mutex_unlock(&(__wg)->device_update_lock); break; } else pfe_label(2): \ - list_for_each_entry_safe (__peer, __temp, &(__wg)->peer_list, peer_list) \ - if (0) pfe_label(3): break; else \ - if (0); else for (__peer = peer_rcu_get(peer); __peer;) if (1) { goto pfe_label(4); pfe_label(5): break; } else while (1) if (1) goto pfe_label(5); else pfe_label(4): \ - if (1) { goto pfe_label(6); pfe_label(7):; } else while (1) if (1) goto pfe_label(3); else while (1) if (1) goto pfe_label(7); else pfe_label(6): \ - if (1) { goto pfe_label(8); pfe_label(9): peer_put(__peer); break; pfe_label(10): peer_put(__peer); } else while (1) if (1) goto pfe_label(9); else while (1) if (1) goto pfe_label(10); else pfe_label(8): - #endif /* _WG_PEER_H */ |