mirror of
https://github.com/facebookexperimental/reverie.git
synced 2025-01-23 13:10:04 +00:00
894ce0fd86
Summary: LLVM-15 has a warning `-Wunused-but-set-variable` which we treat as an error because it's so often diagnostic of a code issue. Unused variables can compromise readability or, worse, performance. This diff either (a) removes an unused variable and, possibly, it's associated code, or (b) qualifies the variable with `[[maybe_unused]]`, mostly in cases where the variable _is_ used, but, eg, in an `assert` statement that isn't present in production code. - If you approve of this diff, please use the "Accept & Ship" button :-) Reviewed By: luciang Differential Revision: D42465119 fbshipit-source-id: 02ad87bf0d56b6ced76912bd1d866a192dbbcbda
66 lines
1.4 KiB
C
66 lines
1.4 KiB
C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <signal.h>
|
|
#include <stdatomic.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
|
|
#define assert(b) \
|
|
if (!(b)) \
|
|
abort();
|
|
|
|
#define TESTS_NLOOPS 100
|
|
|
|
static _Atomic unsigned long* counter;
|
|
|
|
int main(int argc, char* argv[]) {
|
|
sigset_t oldset, set;
|
|
pid_t pid;
|
|
int status;
|
|
|
|
counter = mmap(
|
|
0, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
|
assert((unsigned long)counter != -1UL);
|
|
|
|
if (argc == 2 && strcmp(argv[1], "--block-sigchld") == 0) {
|
|
sigprocmask(SIG_BLOCK, NULL, &set);
|
|
sigaddset(&set, SIGCHLD);
|
|
sigprocmask(SIG_BLOCK, &set, &oldset);
|
|
}
|
|
|
|
for (int i = 0; i < TESTS_NLOOPS; i++) {
|
|
kill(getpid(), SIGCHLD);
|
|
pid = fork();
|
|
// Child
|
|
if (pid == 0) {
|
|
atomic_fetch_add(counter, 1);
|
|
exit(0);
|
|
} else if (pid > 0) {
|
|
atomic_fetch_add(counter, 1);
|
|
} else {
|
|
perror("fork: ");
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
while ((pid = wait(&status)) > 0)
|
|
;
|
|
|
|
unsigned long expected = 2 * TESTS_NLOOPS;
|
|
unsigned long got = atomic_load(counter);
|
|
|
|
printf("counter: expected: %lu got: %lu\n", expected, got);
|
|
|
|
return 0;
|
|
}
|