MEDIUM: threads/lb: Make LB algorithms (lb_*.c) thread-safe

A lock for LB parameters has been added inside the proxy structure and atomic
operations have been used to update server variables releated to lb.

The only significant change is about lb_map. Because the servers status are
updated in the sync-point, we can call recalc_server_map function synchronously
in map_set_server_status_up/down function.
diff --git a/src/lb_fas.c b/src/lb_fas.c
index f8e739b..db292db 100644
--- a/src/lb_fas.c
+++ b/src/lb_fas.c
@@ -63,8 +63,11 @@
 {
 	if (!s->lb_tree)
 		return;
+
+	SPIN_LOCK(LBPRM_LOCK, &s->proxy->lbprm.lock);
 	fas_dequeue_srv(s);
 	fas_queue_srv(s);
+	SPIN_UNLOCK(LBPRM_LOCK, &s->proxy->lbprm.lock);
 }
 
 /* This function updates the server trees according to server <srv>'s new
@@ -111,7 +114,7 @@
 	fas_dequeue_srv(srv);
 	fas_remove_from_tree(srv);
 
-out_update_backend:
+ out_update_backend:
 	/* check/update tot_used, tot_weight */
 	update_backend_weight(p);
  out_update_state:
@@ -274,14 +277,19 @@
 
 	srv = avoided = NULL;
 
+	SPIN_LOCK(LBPRM_LOCK, &p->lbprm.lock);
 	if (p->srv_act)
 		node = eb32_first(&p->lbprm.fas.act);
-	else if (p->lbprm.fbck)
-		return p->lbprm.fbck;
+	else if (p->lbprm.fbck) {
+		srv = p->lbprm.fbck;
+		goto out;
+	}
 	else if (p->srv_bck)
 		node = eb32_first(&p->lbprm.fas.bck);
-	else
-		return NULL;
+	else {
+		srv = NULL;
+		goto out;
+	}
 
 	while (node) {
 		/* OK, we have a server. However, it may be saturated, in which
@@ -304,7 +312,8 @@
 
 	if (!srv)
 		srv = avoided;
-
+  out:
+	SPIN_UNLOCK(LBPRM_LOCK, &p->lbprm.lock);
 	return srv;
 }