diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2016-11-20 11:40:59 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2016-11-20 11:40:59 +0000 |
commit | 6f3180e68d292446fa0aadf1d6823e2decb5daa4 (patch) | |
tree | 891917ce60713f7453a825a06bdeecaf03bd2dba | |
parent | 1da087c079beaa659ed3eb5fded14dde11745f4c (diff) |
Rename SRPL_ENTER() to SRPL_FIRST() and SRPL_NEXT() to SRPL_FOLLOW().
This allows us to introduce SRPL_NEXT() that can be used to start
iterating on an arbitrary member of an srp list, hence without calling
SRPL_ENTER().
ok dlg@, jmatthew@
-rw-r--r-- | share/man/man9/srpl_rc_init.9 | 50 | ||||
-rw-r--r-- | sys/net/rtable.c | 10 | ||||
-rw-r--r-- | sys/netinet/ip_carp.c | 8 | ||||
-rw-r--r-- | sys/sys/srp.h | 13 |
4 files changed, 48 insertions, 33 deletions
diff --git a/share/man/man9/srpl_rc_init.9 b/share/man/man9/srpl_rc_init.9 index 3c5a385751a..87f992aa5c8 100644 --- a/share/man/man9/srpl_rc_init.9 +++ b/share/man/man9/srpl_rc_init.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: srpl_rc_init.9,v 1.10 2016/05/18 03:46:03 dlg Exp $ +.\" $OpenBSD: srpl_rc_init.9,v 1.11 2016/11/20 11:40:58 mpi Exp $ .\" .\" Copyright (c) 2015 David Gwynne <dlg@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 18 2016 $ +.Dd $Mdocdate: November 20 2016 $ .Dt SRPL_RC_INIT 9 .Os .Sh NAME @@ -22,8 +22,9 @@ .Nm SRPL_HEAD , .Nm SRPL_ENTRY , .Nm SRPL_INIT , -.Nm SRPL_ENTER , +.Nm SRPL_FIRST, .Nm SRPL_NEXT , +.Nm SRPL_FOLLOW , .Nm SRPL_FOREACH , .Nm SRPL_LEAVE , .Nm SRPL_EMPTY_LOCKED , @@ -50,9 +51,11 @@ .Fn SRPL_ENTRY "TYPE" .Fn "SRPL_INIT" "SRPL_HEAD *sl" .Ft void * -.Fn "SRPL_ENTER" "struct srp_ref *sr" "SRPL_HEAD *sl" +.Fn "SRPL_FIRST" "struct srp_ref *sr" "SRPL_HEAD *sl" .Ft void * .Fn "SRPL_NEXT" "struct srp_ref *sr" "struct TYPE *listelm" "FIELDNAME" +.Ft void * +.Fn "SRPL_FOLLOW" "struct srp_ref *sr" "struct TYPE *listelm" "FIELDNAME" .Fo "SRPL_FOREACH" .Fa "VARNAME" .Fa "struct srp_ref *sr" @@ -135,20 +138,30 @@ initialises the SRP list .Fa sl to an empty state. .Pp -.Fn SRPL_ENTER -begins iterating over elements in the SRP list -.Fa sl . -The reference to the list item is held via +.Fn SRPL_FIRST +accesses the first element in the SRP list +.Fa sl +and holds its reference via .Fa sr . -Every call to -.Fn SRPL_ENTER -must have a corresponding call to -.Fn SRPL_LEAVE -to release references to the list and its elements. .Pp .Fn SRPL_NEXT accesses the element in the SRP list after -.Fa listelm . +.Fa listelm +and holds its reference via +.Fa sr . +.\".Pp +.\"Every call to +.\".Fn SRPL_FIRST +.\"must have a corresponding call to +.\".Fn SRPL_LEAVE +.\"to release references to the list and its elements. +.Pp +.Fn SRPL_FOLLOW +accesses the element in the SRP list after +.Fa listelm +and swap the previous reference held via +.Fa sr +for the reference of the newly accessed item. .Pp .Fn SRPL_FOREACH creates a loop for traversing the list. @@ -161,8 +174,9 @@ to release references to the list and its elements. .Fn SRPL_LEAVE releases references to the list and its elements held by previous calls to -.Fn SRPL_ENTER , +.Fn SRPL_FIRST, .Fn SRPL_NEXT , +.Fn SRPL_FOLLOW , or .Fn SRPL_FOREACH . .Pp @@ -224,8 +238,9 @@ An srpl_rc declaration can be initialised with the macro. .Sh CONTEXT .Fn SRPL_INIT , -.Fn SRPL_ENTER , +.Fn SRPL_FIRST, .Fn SRPL_NEXT , +.Fn SRPL_FOLLOW , .Fn SRPL_FOREACH , and .Fn SRPL_LEAVE @@ -245,8 +260,9 @@ may be called during autoconf or from process context. An appropriate lock must be held that prevents concurrent modifications to the list. .Sh RETURN VALUES -.Fn SRPL_ENTER , +.Fn SRPL_FIRST , .Fn SRPL_NEXT , +.Fn SRPL_FOLLOW , .Fn SRPL_FIRST_LOCKED , and .Fn SRPL_NEXT_LOCKED diff --git a/sys/net/rtable.c b/sys/net/rtable.c index a82ee8452ca..7656b943bf5 100644 --- a/sys/net/rtable.c +++ b/sys/net/rtable.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtable.c,v 1.54 2016/11/14 10:32:46 mpi Exp $ */ +/* $OpenBSD: rtable.c,v 1.55 2016/11/20 11:40:58 mpi Exp $ */ /* * Copyright (c) 2014-2016 Martin Pieuchot @@ -536,7 +536,7 @@ rtable_lookup(unsigned int rtableid, struct sockaddr *dst, } #ifdef SMALL_KERNEL - rt = SRPL_ENTER(&sr, &an->an_rtlist); + rt = SRPL_FIRST(&sr, &an->an_rtlist); #else SRPL_FOREACH(rt, &sr, &an->an_rtlist, rt_next) { if (prio != RTP_ANY && @@ -583,7 +583,7 @@ rtable_match(unsigned int rtableid, struct sockaddr *dst, uint32_t *src) if (an == NULL) goto out; - rt = SRPL_ENTER(&sr, &an->an_rtlist); + rt = SRPL_FIRST(&sr, &an->an_rtlist); rtref(rt); SRPL_LEAVE(&sr); @@ -614,11 +614,11 @@ rtable_match(unsigned int rtableid, struct sockaddr *dst, uint32_t *src) * the end of the list and then pick the first route. */ - mrt = SRPL_ENTER(&sr, &an->an_rtlist); + mrt = SRPL_FIRST(&sr, &an->an_rtlist); while (hash > threshold && mrt != NULL) { if (mrt->rt_priority == rt->rt_priority) hash -= threshold; - mrt = SRPL_NEXT(&sr, mrt, rt_next); + mrt = SRPL_FOLLOW(&sr, mrt, rt_next); } if (mrt != NULL) { diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index ff3ae78600d..73d959eac26 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.295 2016/10/25 07:21:02 yasuoka Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.296 2016/11/20 11:40:58 mpi Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -1329,7 +1329,7 @@ carp_iamatch(struct ifnet *ifp) struct srp_ref sr; int match = 0; - vhe = SRPL_ENTER(&sr, &sc->carp_vhosts); /* head */ + vhe = SRPL_FIRST(&sr, &sc->carp_vhosts); if (vhe->state == MASTER) match = 1; SRPL_LEAVE(&sr); @@ -1381,7 +1381,7 @@ carp_vhe_match(struct carp_softc *sc, uint8_t *ena) struct srp_ref sr; int match = 0; - vhe = SRPL_ENTER(&sr, &sc->carp_vhosts); /* head */ + vhe = SRPL_FIRST(&sr, &sc->carp_vhosts); match = (vhe->state == MASTER || sc->sc_balancing >= CARP_BAL_IP) && !memcmp(ena, sc->sc_ac.ac_enaddr, ETHER_ADDR_LEN); SRPL_LEAVE(&sr); @@ -2312,7 +2312,7 @@ carp_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *sa, KASSERT(sc->sc_carpdev != NULL); if (sc->cur_vhe == NULL) { - vhe = SRPL_ENTER(&sr, &sc->carp_vhosts); /* head */ + vhe = SRPL_FIRST(&sr, &sc->carp_vhosts); ismaster = (vhe->state == MASTER); SRPL_LEAVE(&sr); } else { diff --git a/sys/sys/srp.h b/sys/sys/srp.h index cedbd20bd87..383135432af 100644 --- a/sys/sys/srp.h +++ b/sys/sys/srp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: srp.h,v 1.12 2016/10/21 06:27:50 dlg Exp $ */ +/* $OpenBSD: srp.h,v 1.13 2016/11/20 11:40:58 mpi Exp $ */ /* * Copyright (c) 2014 Jonathan Matthew <jmatthew@openbsd.org> @@ -110,15 +110,14 @@ struct { \ struct srp se_next; \ } -#define SRPL_ENTER(_sr, _sl) srp_enter((_sr), &(_sl)->sl_head) - -#define SRPL_NEXT(_sr, _e, _ENTRY) \ - srp_follow((_sr), &(_e)->_ENTRY.se_next) +#define SRPL_FIRST(_sr, _sl) srp_enter((_sr), &(_sl)->sl_head) +#define SRPL_NEXT(_sr, _e, _ENTRY) srp_enter((_sr), &(_e)->_ENTRY.se_next) +#define SRPL_FOLLOW(_sr, _e, _ENTRY) srp_follow((_sr), &(_e)->_ENTRY.se_next) #define SRPL_FOREACH(_c, _sr, _sl, _ENTRY) \ - for ((_c) = SRPL_ENTER(_sr, _sl); \ + for ((_c) = SRPL_FIRST(_sr, _sl); \ (_c) != NULL; \ - (_c) = SRPL_NEXT(_sr, _c, _ENTRY)) + (_c) = SRPL_FOLLOW(_sr, _c, _ENTRY)) #define SRPL_LEAVE(_sr) srp_leave((_sr)) |