MINOR: backend: replace the lbprm lock with an rwlock
It was previously a spinlock, and it happens that a number of LB algos
only lock it for lookups, without performing any modification. Let's
first turn it to an rwlock and w-lock it everywhere. This is strictly
identical.
It was carefully checked that every HA_SPIN_LOCK() was turned to
HA_RWLOCK_WRLOCK() and that HA_SPIN_UNLOCK() was turned to
HA_RWLOCK_WRUNLOCK() on this lock. _INIT and _DESTROY were updated too.
diff --git a/src/lb_map.c b/src/lb_map.c
index ef32deb..1432913 100644
--- a/src/lb_map.c
+++ b/src/lb_map.c
@@ -32,11 +32,11 @@
goto out_update_state;
/* FIXME: could be optimized since we know what changed */
- HA_SPIN_LOCK(LBPRM_LOCK, &p->lbprm.lock);
+ HA_RWLOCK_WRLOCK(LBPRM_LOCK, &p->lbprm.lock);
recount_servers(p);
update_backend_weight(p);
recalc_server_map(p);
- HA_SPIN_UNLOCK(LBPRM_LOCK, &p->lbprm.lock);
+ HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
out_update_state:
srv_lb_commit_status(srv);
}
@@ -56,11 +56,11 @@
goto out_update_state;
/* FIXME: could be optimized since we know what changed */
- HA_SPIN_LOCK(LBPRM_LOCK, &p->lbprm.lock);
+ HA_RWLOCK_WRLOCK(LBPRM_LOCK, &p->lbprm.lock);
recount_servers(p);
update_backend_weight(p);
recalc_server_map(p);
- HA_SPIN_UNLOCK(LBPRM_LOCK, &p->lbprm.lock);
+ HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
out_update_state:
srv_lb_commit_status(srv);
}
@@ -216,7 +216,7 @@
int newidx, avoididx;
struct server *srv, *avoided;
- HA_SPIN_LOCK(LBPRM_LOCK, &px->lbprm.lock);
+ HA_RWLOCK_WRLOCK(LBPRM_LOCK, &px->lbprm.lock);
if (px->lbprm.tot_weight == 0) {
avoided = NULL;
goto out;
@@ -248,7 +248,7 @@
px->lbprm.map.rr_idx = avoididx;
out:
- HA_SPIN_UNLOCK(LBPRM_LOCK, &px->lbprm.lock);
+ HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &px->lbprm.lock);
/* return NULL or srvtoavoid if found */
return avoided;
}
@@ -265,10 +265,10 @@
{
struct server *srv = NULL;
- HA_SPIN_LOCK(LBPRM_LOCK, &px->lbprm.lock);
+ HA_RWLOCK_WRLOCK(LBPRM_LOCK, &px->lbprm.lock);
if (px->lbprm.tot_weight)
srv = px->lbprm.map.srv[hash % px->lbprm.tot_weight];
- HA_SPIN_UNLOCK(LBPRM_LOCK, &px->lbprm.lock);
+ HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &px->lbprm.lock);
return srv;
}