]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: compression: Use the new _HA_ATOMIC_* macros.
authorOlivier Houchard <ohouchard@haproxy.com>
Fri, 8 Mar 2019 17:50:27 +0000 (18:50 +0100)
committerOlivier Houchard <cognet@ci0.org>
Mon, 11 Mar 2019 16:02:38 +0000 (17:02 +0100)
Use the new _HA_ATOMIC_* macros and add barriers where needed.

src/compression.c
src/flt_http_comp.c

index b0307b23ebdba17c5e748052cf754192863c5822..11e09d8085ea94d6cfc015c7b59d35287fa59692 100644 (file)
@@ -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();
 }
 
 /**************************
index 3c2ce365ec07b8134248e67be7206183d345d78a..6cad8e1b9008381a7dbd8f9bce834f8ad1d635bb 100644 (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) {
                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;