MEDIUM: threads/server: Add a lock per server and atomically update server vars
The server's lock is use, among other things, to lock acces to the active
connection list of a server.
diff --git a/include/proto/server.h b/include/proto/server.h
index b101b3e..ff4ec77 100644
--- a/include/proto/server.h
+++ b/include/proto/server.h
@@ -64,10 +64,9 @@
/* increase the number of cumulated connections on the designated server */
static void inline srv_inc_sess_ctr(struct server *s)
{
- s->counters.cum_sess++;
- update_freq_ctr(&s->sess_per_sec, 1);
- if (s->sess_per_sec.curr_ctr > s->counters.sps_max)
- s->counters.sps_max = s->sess_per_sec.curr_ctr;
+ HA_ATOMIC_ADD(&s->counters.cum_sess, 1);
+ HA_ATOMIC_UPDATE_MAX(&s->counters.sps_max,
+ update_freq_ctr(&s->sess_per_sec, 1));
}
/* set the time of last session on the designated server */
diff --git a/include/proto/stream.h b/include/proto/stream.h
index 00f452c..aae7d34 100644
--- a/include/proto/stream.h
+++ b/include/proto/stream.h
@@ -262,17 +262,23 @@
static void inline stream_add_srv_conn(struct stream *sess, struct server *srv)
{
+ SPIN_LOCK(SERVER_LOCK, &srv->lock);
sess->srv_conn = srv;
LIST_ADD(&srv->actconns, &sess->by_srv);
+ SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
}
static void inline stream_del_srv_conn(struct stream *sess)
{
- if (!sess->srv_conn)
+ struct server *srv = sess->srv_conn;
+
+ if (!srv)
return;
+ SPIN_LOCK(SERVER_LOCK, &srv->lock);
sess->srv_conn = NULL;
LIST_DEL(&sess->by_srv);
+ SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
}
static void inline stream_init_srv_conn(struct stream *sess)