CLEANUP: atomic: add an explicit _FETCH variant for add/sub/and/or

Currently our atomic ops return a value but it's never known whether
the fetch is done before or after the operation, which causes some
confusion each time the value is desired. Let's create an explicit
variant of these operations suffixed with _FETCH to explicitly mention
that the fetch occurs after the operation, and make use of it at the
few call places.
diff --git a/src/backend.c b/src/backend.c
index 62be510..1b9c704 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -1703,7 +1703,7 @@
 		int count;
 
 		s->flags |= SF_CURR_SESS;
-		count = _HA_ATOMIC_ADD(&srv->cur_sess, 1);
+		count = _HA_ATOMIC_ADD_FETCH(&srv->cur_sess, 1);
 		HA_ATOMIC_UPDATE_MAX(&srv->counters.cur_sess_max, count);
 		if (s->be->lbprm.server_take_conn)
 			s->be->lbprm.server_take_conn(srv, 0);
diff --git a/src/dict.c b/src/dict.c
index f3c2a73..ba076d0 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -116,7 +116,7 @@
 	if (!de)
 		return;
 
-	if (HA_ATOMIC_SUB(&de->refcount, 1) != 0)
+	if (HA_ATOMIC_SUB_FETCH(&de->refcount, 1) != 0)
 		return;
 
 	HA_RWLOCK_WRLOCK(DICT_LOCK, &d->rwlock);
diff --git a/src/fd.c b/src/fd.c
index 8d671bd..588271f 100644
--- a/src/fd.c
+++ b/src/fd.c
@@ -374,7 +374,7 @@
 	int ret = -1;
 
 #ifndef HA_HAVE_CAS_DW
-	if (_HA_ATOMIC_OR(&fdtab[fd].running_mask, tid_bit) == tid_bit) {
+	if (_HA_ATOMIC_OR_FETCH(&fdtab[fd].running_mask, tid_bit) == tid_bit) {
 		HA_RWLOCK_WRLOCK(OTHER_LOCK, &fd_mig_lock);
 		if (fdtab[fd].owner == expected_owner) {
 			fdtab[fd].thread_mask = tid_bit;
@@ -388,7 +388,7 @@
 
 	new_masks[0] = new_masks[1] = tid_bit;
 
-	old_masks[0] = _HA_ATOMIC_OR(&fdtab[fd].running_mask, tid_bit);
+	old_masks[0] = _HA_ATOMIC_OR_FETCH(&fdtab[fd].running_mask, tid_bit);
 	old_masks[1] = fdtab[fd].thread_mask;
 
 	/* protect ourself against a delete then an insert for the same fd,
diff --git a/src/haproxy.c b/src/haproxy.c
index e7d30b0..a8f2274 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2385,7 +2385,7 @@
 			int i;
 
 			if (stopping) {
-				if (_HA_ATOMIC_OR(&stopping_thread_mask, tid_bit) == tid_bit) {
+				if (_HA_ATOMIC_OR_FETCH(&stopping_thread_mask, tid_bit) == tid_bit) {
 					/* notify all threads that stopping was just set */
 					for (i = 0; i < global.nbthread; i++)
 						if (((all_threads_mask & ~stopping_thread_mask) >> i) & 1)
diff --git a/src/proxy.c b/src/proxy.c
index fb60bf4..1b2cd2e 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -2126,7 +2126,7 @@
 
 	s->be = be;
 	HA_ATOMIC_UPDATE_MAX(&be->be_counters.conn_max,
-			     HA_ATOMIC_ADD(&be->beconn, 1));
+			     HA_ATOMIC_ADD_FETCH(&be->beconn, 1));
 	proxy_inc_be_ctr(be);
 
 	/* assign new parameters to the stream from the new backend */
diff --git a/src/queue.c b/src/queue.c
index e5ab5db..58f9875 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -400,7 +400,7 @@
 	if (srv) {
 		unsigned int old_max, new_max;
 
-		new_max = _HA_ATOMIC_ADD(&srv->nbpend, 1);
+		new_max = _HA_ATOMIC_ADD_FETCH(&srv->nbpend, 1);
 		old_max = srv->counters.nbpend_max;
 		while (new_max > old_max) {
 			if (likely(_HA_ATOMIC_CAS(&srv->counters.nbpend_max, &old_max, new_max)))
@@ -416,7 +416,7 @@
 	else {
 		unsigned int old_max, new_max;
 
-		new_max = _HA_ATOMIC_ADD(&px->nbpend, 1);
+		new_max = _HA_ATOMIC_ADD_FETCH(&px->nbpend, 1);
 		old_max = px->be_counters.nbpend_max;
 		while (new_max > old_max) {
 			if (likely(_HA_ATOMIC_CAS(&px->be_counters.nbpend_max, &old_max, new_max)))
diff --git a/src/ssl_sock.c b/src/ssl_sock.c
index b06c2ae..525d02f 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -1943,7 +1943,7 @@
 	 * number */
 	if (X509_set_version(newcrt, 2L) != 1)
 		goto mkcert_error;
-	ASN1_INTEGER_set(X509_get_serialNumber(newcrt), _HA_ATOMIC_ADD(&ssl_ctx_serial, 1));
+	ASN1_INTEGER_set(X509_get_serialNumber(newcrt), _HA_ATOMIC_ADD_FETCH(&ssl_ctx_serial, 1));
 
 	/* Set duration for the certificate */
 	if (!X509_gmtime_adj(X509_getm_notBefore(newcrt), (long)-60*60*24) ||
diff --git a/src/task.c b/src/task.c
index be3262a..59f6ff7 100644
--- a/src/task.c
+++ b/src/task.c
@@ -585,7 +585,7 @@
 				HA_ATOMIC_ADD(&profile_entry->cpu_time, cpu);
 			}
 
-			state = _HA_ATOMIC_AND(&t->state, ~TASK_RUNNING);
+			state = _HA_ATOMIC_AND_FETCH(&t->state, ~TASK_RUNNING);
 			if (unlikely(state & TASK_KILLED)) {
 				task_unlink_wq(t);
 				__task_free(t);