MEDIUM: compression: 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:50:27 +01:00 committed by Olivier Houchard
parent cb6c9274ae
commit 43da3430f1
2 changed files with 24 additions and 19 deletions

View File

@ -168,7 +168,8 @@ static inline int init_comp_ctx(struct comp_ctx **comp_ctx)
(*comp_ctx)->direct_len = 0; (*comp_ctx)->direct_len = 0;
(*comp_ctx)->queued = BUF_NULL; (*comp_ctx)->queued = BUF_NULL;
#elif defined(USE_ZLIB) #elif defined(USE_ZLIB)
HA_ATOMIC_ADD(&zlib_used_memory, sizeof(struct comp_ctx)); _HA_ATOMIC_ADD(&zlib_used_memory, sizeof(struct comp_ctx));
__ha_barrier_atomic_store();
strm = &(*comp_ctx)->strm; strm = &(*comp_ctx)->strm;
strm->zalloc = alloc_zlib; strm->zalloc = alloc_zlib;
@ -190,7 +191,8 @@ static inline int deinit_comp_ctx(struct comp_ctx **comp_ctx)
*comp_ctx = NULL; *comp_ctx = NULL;
#ifdef USE_ZLIB #ifdef USE_ZLIB
HA_ATOMIC_SUB(&zlib_used_memory, sizeof(struct comp_ctx)); _HA_ATOMIC_SUB(&zlib_used_memory, sizeof(struct comp_ctx));
__ha_barrier_atomic_store();
#endif #endif
return 0; return 0;
} }
@ -459,8 +461,10 @@ static void *alloc_zlib(void *opaque, unsigned int items, unsigned int size)
ctx->zlib_pending_buf = buf = pool_alloc(pool); ctx->zlib_pending_buf = buf = pool_alloc(pool);
break; break;
} }
if (buf != NULL) if (buf != NULL) {
HA_ATOMIC_ADD(&zlib_used_memory, pool->size); _HA_ATOMIC_ADD(&zlib_used_memory, pool->size);
__ha_barrier_atomic_store();
}
end: end:
@ -491,7 +495,8 @@ static void free_zlib(void *opaque, void *ptr)
pool = zlib_pool_pending_buf; pool = zlib_pool_pending_buf;
pool_free(pool, ptr); pool_free(pool, ptr);
HA_ATOMIC_SUB(&zlib_used_memory, pool->size); _HA_ATOMIC_SUB(&zlib_used_memory, pool->size);
__ha_barrier_atomic_store();
} }
/************************** /**************************

View File

@ -286,14 +286,14 @@ comp_http_payload(struct stream *s, struct filter *filter, struct http_msg *msg,
if (st->comp_ctx && st->comp_ctx->cur_lvl > 0) { if (st->comp_ctx && st->comp_ctx->cur_lvl > 0) {
update_freq_ctr(&global.comp_bps_in, consumed); update_freq_ctr(&global.comp_bps_in, consumed);
HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_in, consumed); _HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_in, consumed);
HA_ATOMIC_ADD(&s->be->be_counters.comp_in, consumed); _HA_ATOMIC_ADD(&s->be->be_counters.comp_in, consumed);
update_freq_ctr(&global.comp_bps_out, to_forward); update_freq_ctr(&global.comp_bps_out, to_forward);
HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_out, to_forward); _HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_out, to_forward);
HA_ATOMIC_ADD(&s->be->be_counters.comp_out, to_forward); _HA_ATOMIC_ADD(&s->be->be_counters.comp_out, to_forward);
} else { } else {
HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_byp, consumed); _HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_byp, consumed);
HA_ATOMIC_ADD(&s->be->be_counters.comp_byp, consumed); _HA_ATOMIC_ADD(&s->be->be_counters.comp_byp, consumed);
} }
return to_forward; return to_forward;
@ -461,9 +461,9 @@ comp_http_end(struct stream *s, struct filter *filter,
goto end; goto end;
if (strm_fe(s)->mode == PR_MODE_HTTP) if (strm_fe(s)->mode == PR_MODE_HTTP)
HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.p.http.comp_rsp, 1); _HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.p.http.comp_rsp, 1);
if ((s->flags & SF_BE_ASSIGNED) && (s->be->mode == PR_MODE_HTTP)) if ((s->flags & SF_BE_ASSIGNED) && (s->be->mode == PR_MODE_HTTP))
HA_ATOMIC_ADD(&s->be->be_counters.p.http.comp_rsp, 1); _HA_ATOMIC_ADD(&s->be->be_counters.p.http.comp_rsp, 1);
end: end:
return 1; return 1;
} }
@ -1265,11 +1265,11 @@ http_compression_buffer_end(struct comp_state *st, struct stream *s,
/* update input rate */ /* update input rate */
if (st->comp_ctx && st->comp_ctx->cur_lvl > 0) { if (st->comp_ctx && st->comp_ctx->cur_lvl > 0) {
update_freq_ctr(&global.comp_bps_in, st->consumed); update_freq_ctr(&global.comp_bps_in, st->consumed);
HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_in, st->consumed); _HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_in, st->consumed);
HA_ATOMIC_ADD(&s->be->be_counters.comp_in, st->consumed); _HA_ATOMIC_ADD(&s->be->be_counters.comp_in, st->consumed);
} else { } else {
HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_byp, st->consumed); _HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_byp, st->consumed);
HA_ATOMIC_ADD(&s->be->be_counters.comp_byp, st->consumed); _HA_ATOMIC_ADD(&s->be->be_counters.comp_byp, st->consumed);
} }
/* copy the remaining data in the tmp buffer. */ /* copy the remaining data in the tmp buffer. */
@ -1292,8 +1292,8 @@ http_compression_buffer_end(struct comp_state *st, struct stream *s,
if (st->comp_ctx && st->comp_ctx->cur_lvl > 0) { if (st->comp_ctx && st->comp_ctx->cur_lvl > 0) {
update_freq_ctr(&global.comp_bps_out, to_forward); update_freq_ctr(&global.comp_bps_out, to_forward);
HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_out, to_forward); _HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_out, to_forward);
HA_ATOMIC_ADD(&s->be->be_counters.comp_out, to_forward); _HA_ATOMIC_ADD(&s->be->be_counters.comp_out, to_forward);
} }
return to_forward; return to_forward;