MEDIUM: peers: Use the new _HA_ATOMIC_* macros.

Use the new _HA_ATOMIC_* macros and add barriers where needed.
This commit is contained in:
Olivier Houchard 2019-03-08 18:53:43 +01:00 committed by Olivier Houchard
parent 20872763dd
commit ed87989ab5

View File

@ -608,8 +608,8 @@ static void peer_session_release(struct appctx *appctx)
/* peer session identified */ /* peer session identified */
if (peer) { if (peer) {
if (appctx->st0 == PEER_SESS_ST_WAITMSG) if (appctx->st0 == PEER_SESS_ST_WAITMSG)
HA_ATOMIC_SUB(&connected_peers, 1); _HA_ATOMIC_SUB(&connected_peers, 1);
HA_ATOMIC_SUB(&active_peers, 1); _HA_ATOMIC_SUB(&active_peers, 1);
HA_SPIN_LOCK(PEER_LOCK, &peer->lock); HA_SPIN_LOCK(PEER_LOCK, &peer->lock);
if (peer->appctx == appctx) { if (peer->appctx == appctx) {
/* Re-init current table pointers to force announcement on re-connect */ /* Re-init current table pointers to force announcement on re-connect */
@ -2043,7 +2043,7 @@ switchstate:
curpeer->appctx = appctx; curpeer->appctx = appctx;
appctx->ctx.peers.ptr = curpeer; appctx->ctx.peers.ptr = curpeer;
appctx->st0 = PEER_SESS_ST_SENDSUCCESS; appctx->st0 = PEER_SESS_ST_SENDSUCCESS;
HA_ATOMIC_ADD(&active_peers, 1); _HA_ATOMIC_ADD(&active_peers, 1);
/* fall through */ /* fall through */
} }
case PEER_SESS_ST_SENDSUCCESS: { case PEER_SESS_ST_SENDSUCCESS: {
@ -2067,7 +2067,7 @@ switchstate:
init_accepted_peer(curpeer, curpeers); init_accepted_peer(curpeer, curpeers);
/* switch to waiting message state */ /* switch to waiting message state */
HA_ATOMIC_ADD(&connected_peers, 1); _HA_ATOMIC_ADD(&connected_peers, 1);
appctx->st0 = PEER_SESS_ST_WAITMSG; appctx->st0 = PEER_SESS_ST_WAITMSG;
goto switchstate; goto switchstate;
} }
@ -2131,7 +2131,7 @@ switchstate:
appctx->st0 = PEER_SESS_ST_END; appctx->st0 = PEER_SESS_ST_END;
goto switchstate; goto switchstate;
} }
HA_ATOMIC_ADD(&connected_peers, 1); _HA_ATOMIC_ADD(&connected_peers, 1);
appctx->st0 = PEER_SESS_ST_WAITMSG; appctx->st0 = PEER_SESS_ST_WAITMSG;
/* fall through */ /* fall through */
} }
@ -2191,7 +2191,7 @@ send_msgs:
} }
case PEER_SESS_ST_EXIT: case PEER_SESS_ST_EXIT:
if (prev_state == PEER_SESS_ST_WAITMSG) if (prev_state == PEER_SESS_ST_WAITMSG)
HA_ATOMIC_SUB(&connected_peers, 1); _HA_ATOMIC_SUB(&connected_peers, 1);
prev_state = appctx->st0; prev_state = appctx->st0;
if (peer_send_status_errormsg(appctx) == -1) if (peer_send_status_errormsg(appctx) == -1)
goto out; goto out;
@ -2199,7 +2199,7 @@ send_msgs:
goto switchstate; goto switchstate;
case PEER_SESS_ST_ERRSIZE: { case PEER_SESS_ST_ERRSIZE: {
if (prev_state == PEER_SESS_ST_WAITMSG) if (prev_state == PEER_SESS_ST_WAITMSG)
HA_ATOMIC_SUB(&connected_peers, 1); _HA_ATOMIC_SUB(&connected_peers, 1);
prev_state = appctx->st0; prev_state = appctx->st0;
if (peer_send_error_size_limitmsg(appctx) == -1) if (peer_send_error_size_limitmsg(appctx) == -1)
goto out; goto out;
@ -2208,7 +2208,7 @@ send_msgs:
} }
case PEER_SESS_ST_ERRPROTO: { case PEER_SESS_ST_ERRPROTO: {
if (prev_state == PEER_SESS_ST_WAITMSG) if (prev_state == PEER_SESS_ST_WAITMSG)
HA_ATOMIC_SUB(&connected_peers, 1); _HA_ATOMIC_SUB(&connected_peers, 1);
prev_state = appctx->st0; prev_state = appctx->st0;
if (peer_send_error_protomsg(appctx) == -1) if (peer_send_error_protomsg(appctx) == -1)
goto out; goto out;
@ -2218,7 +2218,7 @@ send_msgs:
} }
case PEER_SESS_ST_END: { case PEER_SESS_ST_END: {
if (prev_state == PEER_SESS_ST_WAITMSG) if (prev_state == PEER_SESS_ST_WAITMSG)
HA_ATOMIC_SUB(&connected_peers, 1); _HA_ATOMIC_SUB(&connected_peers, 1);
prev_state = appctx->st0; prev_state = appctx->st0;
if (curpeer) { if (curpeer) {
HA_SPIN_UNLOCK(PEER_LOCK, &curpeer->lock); HA_SPIN_UNLOCK(PEER_LOCK, &curpeer->lock);
@ -2264,7 +2264,7 @@ static void peer_session_forceshutdown(struct appctx *appctx)
return; return;
if (appctx->st0 == PEER_SESS_ST_WAITMSG) if (appctx->st0 == PEER_SESS_ST_WAITMSG)
HA_ATOMIC_SUB(&connected_peers, 1); _HA_ATOMIC_SUB(&connected_peers, 1);
appctx->st0 = PEER_SESS_ST_END; appctx->st0 = PEER_SESS_ST_END;
appctx_wakeup(appctx); appctx_wakeup(appctx);
} }
@ -2355,7 +2355,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
peer->appctx = appctx; peer->appctx = appctx;
task_wakeup(s->task, TASK_WOKEN_INIT); task_wakeup(s->task, TASK_WOKEN_INIT);
HA_ATOMIC_ADD(&active_peers, 1); _HA_ATOMIC_ADD(&active_peers, 1);
return appctx; return appctx;
/* Error unrolling */ /* Error unrolling */
@ -2512,7 +2512,7 @@ static struct task *process_peer_sync(struct task * task, void *context, unsigne
/* We've just received the signal */ /* We've just received the signal */
if (!(peers->flags & PEERS_F_DONOTSTOP)) { if (!(peers->flags & PEERS_F_DONOTSTOP)) {
/* add DO NOT STOP flag if not present */ /* add DO NOT STOP flag if not present */
HA_ATOMIC_ADD(&jobs, 1); _HA_ATOMIC_ADD(&jobs, 1);
peers->flags |= PEERS_F_DONOTSTOP; peers->flags |= PEERS_F_DONOTSTOP;
ps = peers->local; ps = peers->local;
for (st = ps->tables; st ; st = st->next) for (st = ps->tables; st ; st = st->next)
@ -2537,7 +2537,7 @@ static struct task *process_peer_sync(struct task * task, void *context, unsigne
if (ps->flags & PEER_F_TEACH_COMPLETE) { if (ps->flags & PEER_F_TEACH_COMPLETE) {
if (peers->flags & PEERS_F_DONOTSTOP) { if (peers->flags & PEERS_F_DONOTSTOP) {
/* resync of new process was complete, current process can die now */ /* resync of new process was complete, current process can die now */
HA_ATOMIC_SUB(&jobs, 1); _HA_ATOMIC_SUB(&jobs, 1);
peers->flags &= ~PEERS_F_DONOTSTOP; peers->flags &= ~PEERS_F_DONOTSTOP;
for (st = ps->tables; st ; st = st->next) for (st = ps->tables; st ; st = st->next)
st->table->syncing--; st->table->syncing--;
@ -2561,7 +2561,7 @@ static struct task *process_peer_sync(struct task * task, void *context, unsigne
/* Other error cases */ /* Other error cases */
if (peers->flags & PEERS_F_DONOTSTOP) { if (peers->flags & PEERS_F_DONOTSTOP) {
/* unable to resync new process, current process can die now */ /* unable to resync new process, current process can die now */
HA_ATOMIC_SUB(&jobs, 1); _HA_ATOMIC_SUB(&jobs, 1);
peers->flags &= ~PEERS_F_DONOTSTOP; peers->flags &= ~PEERS_F_DONOTSTOP;
for (st = ps->tables; st ; st = st->next) for (st = ps->tables; st ; st = st->next)
st->table->syncing--; st->table->syncing--;