]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: chunks: Make sure trash_size is only set once.
authorOlivier Houchard <ohouchard@haproxy.com>
Fri, 7 Jun 2019 12:35:35 +0000 (14:35 +0200)
committerOlivier Houchard <cognet@ci0.org>
Fri, 7 Jun 2019 12:45:44 +0000 (14:45 +0200)
The trash_size variable is shared by all threads, and is set by all threads,
when alloc_trash_buffers() is called. To make sure it's set only once,
to silence a harmless data race, use a CAS to set it, and only set it if it
was 0.

src/chunk.c

index 8e77858c3af159f939a41387e7081b65a239f617..344b28d20a99879bdff2198699d77c557d2ffd65 100644 (file)
@@ -68,8 +68,9 @@ struct buffer *get_trash_chunk(void)
  */
 static int alloc_trash_buffers(int bufsize)
 {
+       int old = 0;
        chunk_init(&trash, my_realloc2(trash.area, bufsize), bufsize);
-       trash_size = bufsize;
+       HA_ATOMIC_CAS(&trash_size, &old, bufsize);
        trash_buf1 = (char *)my_realloc2(trash_buf1, bufsize);
        trash_buf2 = (char *)my_realloc2(trash_buf2, bufsize);
        return trash.area && trash_buf1 && trash_buf2;