From: Olivier Houchard Date: Fri, 8 Mar 2019 17:50:27 +0000 (+0100) Subject: MEDIUM: compression: Use the new _HA_ATOMIC_* macros. X-Git-Tag: v2.0-dev2~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43da3430f10ed676f5cd42d49a9bc23a3ea2c855;p=thirdparty%2Fhaproxy.git MEDIUM: compression: Use the new _HA_ATOMIC_* macros. Use the new _HA_ATOMIC_* macros and add barriers where needed. --- diff --git a/src/compression.c b/src/compression.c index b0307b23eb..11e09d8085 100644 --- a/src/compression.c +++ b/src/compression.c @@ -168,7 +168,8 @@ static inline int init_comp_ctx(struct comp_ctx **comp_ctx) (*comp_ctx)->direct_len = 0; (*comp_ctx)->queued = BUF_NULL; #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->zalloc = alloc_zlib; @@ -190,7 +191,8 @@ static inline int deinit_comp_ctx(struct comp_ctx **comp_ctx) *comp_ctx = NULL; #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 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); break; } - if (buf != NULL) - HA_ATOMIC_ADD(&zlib_used_memory, pool->size); + if (buf != NULL) { + _HA_ATOMIC_ADD(&zlib_used_memory, pool->size); + __ha_barrier_atomic_store(); + } end: @@ -491,7 +495,8 @@ static void free_zlib(void *opaque, void *ptr) pool = zlib_pool_pending_buf; pool_free(pool, ptr); - HA_ATOMIC_SUB(&zlib_used_memory, pool->size); + _HA_ATOMIC_SUB(&zlib_used_memory, pool->size); + __ha_barrier_atomic_store(); } /************************** diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index 3c2ce365ec..6cad8e1b90 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -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) { update_freq_ctr(&global.comp_bps_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(&strm_fe(s)->fe_counters.comp_in, consumed); + _HA_ATOMIC_ADD(&s->be->be_counters.comp_in, consumed); update_freq_ctr(&global.comp_bps_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(&strm_fe(s)->fe_counters.comp_out, to_forward); + _HA_ATOMIC_ADD(&s->be->be_counters.comp_out, to_forward); } else { - HA_ATOMIC_ADD(&strm_fe(s)->fe_counters.comp_byp, consumed); - HA_ATOMIC_ADD(&s->be->be_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); } return to_forward; @@ -461,9 +461,9 @@ comp_http_end(struct stream *s, struct filter *filter, goto end; 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)) - 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: return 1; } @@ -1265,11 +1265,11 @@ http_compression_buffer_end(struct comp_state *st, struct stream *s, /* update input rate */ if (st->comp_ctx && st->comp_ctx->cur_lvl > 0) { update_freq_ctr(&global.comp_bps_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(&strm_fe(s)->fe_counters.comp_in, st->consumed); + _HA_ATOMIC_ADD(&s->be->be_counters.comp_in, st->consumed); } else { - 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(&strm_fe(s)->fe_counters.comp_byp, st->consumed); + _HA_ATOMIC_ADD(&s->be->be_counters.comp_byp, st->consumed); } /* 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) { update_freq_ctr(&global.comp_bps_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(&strm_fe(s)->fe_counters.comp_out, to_forward); + _HA_ATOMIC_ADD(&s->be->be_counters.comp_out, to_forward); } return to_forward;