|
40 | 40 | #include <netinet/tcp.h>
|
41 | 41 | #include <pthread.h>
|
42 | 42 | #include <signal.h>
|
| 43 | +#include <stdatomic.h> |
43 | 44 | #include <stdio.h>
|
44 | 45 | #include <stdlib.h>
|
45 | 46 | #include <string.h>
|
@@ -81,11 +82,11 @@ static int num_threads = 1;
|
81 | 82 |
|
82 | 83 | static char *udaddr = "";
|
83 | 84 |
|
84 |
| -static volatile uint64_t num_requests = 0; |
| 85 | +static volatile _Atomic uint64_t num_requests = 0; |
85 | 86 | static volatile uint64_t max_requests = 0;
|
86 |
| -static volatile uint64_t good_requests = 0; |
87 |
| -static volatile uint64_t bad_requests = 0; |
88 |
| -static volatile uint64_t socket_errors = 0; |
| 87 | +static volatile _Atomic uint64_t good_requests = 0; |
| 88 | +static volatile _Atomic uint64_t bad_requests = 0; |
| 89 | +static volatile _Atomic uint64_t socket_errors = 0; |
89 | 90 | static volatile uint64_t in_bytes = 0;
|
90 | 91 | static volatile uint64_t out_bytes = 0;
|
91 | 92 |
|
@@ -214,7 +215,7 @@ static void *worker(void *arg)
|
214 | 215 | if (number_of_errors_logged % 100 == 0) {
|
215 | 216 | fprintf(stderr, "EPOLLERR caused by unknown error\n");
|
216 | 217 | }
|
217 |
| - __sync_fetch_and_add(&socket_errors, 1); |
| 218 | + atomic_fetch_add(&socket_errors, 1); |
218 | 219 | close(ec->fd);
|
219 | 220 | if (num_requests > max_requests)
|
220 | 221 | continue;
|
@@ -284,14 +285,14 @@ static void *worker(void *arg)
|
284 | 285 | if (!ret) {
|
285 | 286 | close(ec->fd);
|
286 | 287 |
|
287 |
| - int m = __sync_fetch_and_add(&num_requests, 1); |
| 288 | + int m = atomic_fetch_add(&num_requests, 1); |
288 | 289 |
|
289 | 290 | if (max_requests && (m + 1 > (int) max_requests))
|
290 |
| - __sync_fetch_and_sub(&num_requests, 1); |
| 291 | + atomic_fetch_sub(&num_requests, 1); |
291 | 292 | else if (ec->flags & BAD_REQUEST)
|
292 |
| - __sync_fetch_and_add(&bad_requests, 1); |
| 293 | + atomic_fetch_add(&bad_requests, 1); |
293 | 294 | else
|
294 |
| - __sync_fetch_and_add(&good_requests, 1); |
| 295 | + atomic_fetch_add(&good_requests, 1); |
295 | 296 |
|
296 | 297 | if (max_requests && (m + 1 >= (int) max_requests)) {
|
297 | 298 | end_time();
|
|
0 commit comments