clang-format

This commit is contained in:
2024-09-10 13:03:02 -04:00
parent 53c617d779
commit d66450e427
381 changed files with 28864 additions and 34170 deletions

View File

@@ -41,7 +41,7 @@
#define MAXCOUNT 64
#define PONGLOOPS 1000
//#define VERBOSE_PONG
// #define VERBOSE_PONG
static struct usem sems[MAXCOUNT];
static unsigned nsems;
@@ -55,31 +55,27 @@ static unsigned nsems;
* that way each task process has its own file handles and they don't
* interfere with each other if file handle locking isn't so great.
*/
void
pong_prep(unsigned groupid, unsigned count)
{
unsigned i;
void pong_prep(unsigned groupid, unsigned count) {
unsigned i;
if (count > MAXCOUNT) {
err(1, "pong: too many pongers -- recompile pong.c");
}
for (i=0; i<count; i++) {
usem_init(&sems[i], "sem:pong-%u-%u", groupid, i);
}
nsems = count;
if (count > MAXCOUNT) {
err(1, "pong: too many pongers -- recompile pong.c");
}
for (i = 0; i < count; i++) {
usem_init(&sems[i], "sem:pong-%u-%u", groupid, i);
}
nsems = count;
}
void
pong_cleanup(unsigned groupid, unsigned count)
{
unsigned i;
void pong_cleanup(unsigned groupid, unsigned count) {
unsigned i;
assert(nsems == count);
(void)groupid;
for (i=0; i<count; i++) {
usem_cleanup(&sems[i]);
}
assert(nsems == count);
(void)groupid;
for (i = 0; i < count; i++) {
usem_cleanup(&sems[i]);
}
}
/*
@@ -87,36 +83,33 @@ pong_cleanup(unsigned groupid, unsigned count)
* If we're id 0, don't wait the first go so things start, but do
* wait the last go.
*/
static
void
pong_cyclic(unsigned id)
{
unsigned i;
unsigned nextid;
static void pong_cyclic(unsigned id) {
unsigned i;
unsigned nextid;
nextid = (id + 1) % nsems;
for (i=0; i<PONGLOOPS; i++) {
if (i > 0 || id > 0) {
P(&sems[id]);
}
nextid = (id + 1) % nsems;
for (i = 0; i < PONGLOOPS; i++) {
if (i > 0 || id > 0) {
P(&sems[id]);
}
#ifdef VERBOSE_PONG
printf(" %u", id);
printf(" %u", id);
#else
if (nextid == 0 && i % 16 == 0) {
putchar('.');
}
if (nextid == 0 && i % 16 == 0) {
putchar('.');
}
#endif
V(&sems[nextid]);
}
if (id == 0) {
P(&sems[id]);
}
V(&sems[nextid]);
}
if (id == 0) {
P(&sems[id]);
}
#ifdef VERBOSE_PONG
putchar('\n');
putchar('\n');
#else
if (nextid == 0) {
putchar('\n');
}
if (nextid == 0) {
putchar('\n');
}
#endif
}
@@ -124,88 +117,80 @@ pong_cyclic(unsigned id)
* Pong back and forth. This runs the tasks with middle numbers more
* often.
*/
static
void
pong_reciprocating(unsigned id)
{
unsigned i, n;
unsigned nextfwd, nextback;
unsigned gofwd = 1;
static void pong_reciprocating(unsigned id) {
unsigned i, n;
unsigned nextfwd, nextback;
unsigned gofwd = 1;
if (id == 0) {
nextfwd = nextback = 1;
n = PONGLOOPS;
}
else if (id == nsems - 1) {
nextfwd = nextback = nsems - 2;
n = PONGLOOPS;
}
else {
nextfwd = id + 1;
nextback = id - 1;
n = PONGLOOPS * 2;
}
if (id == 0) {
nextfwd = nextback = 1;
n = PONGLOOPS;
} else if (id == nsems - 1) {
nextfwd = nextback = nsems - 2;
n = PONGLOOPS;
} else {
nextfwd = id + 1;
nextback = id - 1;
n = PONGLOOPS * 2;
}
for (i=0; i<n; i++) {
if (i > 0 || id > 0) {
P(&sems[id]);
}
for (i = 0; i < n; i++) {
if (i > 0 || id > 0) {
P(&sems[id]);
}
#ifdef VERBOSE_PONG
printf(" %u", id);
printf(" %u", id);
#else
if (id == 0 && i % 16 == 0) {
putchar('.');
}
if (id == 0 && i % 16 == 0) {
putchar('.');
}
#endif
if (gofwd) {
V(&sems[nextfwd]);
gofwd = 0;
}
else {
V(&sems[nextback]);
gofwd = 1;
}
}
if (id == 0) {
P(&sems[id]);
}
if (gofwd) {
V(&sems[nextfwd]);
gofwd = 0;
} else {
V(&sems[nextback]);
gofwd = 1;
}
}
if (id == 0) {
P(&sems[id]);
}
#ifdef VERBOSE_PONG
putchar('\n');
putchar('\n');
#else
if (id == 0) {
putchar('\n');
}
if (id == 0) {
putchar('\n');
}
#endif
}
/*
* Do the pong thing.
*/
void
pong(unsigned groupid, unsigned id)
{
unsigned idfwd, idback;
void pong(unsigned groupid, unsigned id) {
unsigned idfwd, idback;
(void)groupid;
(void)groupid;
idfwd = (id + 1) % nsems;
idback = (id + nsems - 1) % nsems;
usem_open(&sems[id]);
usem_open(&sems[idfwd]);
usem_open(&sems[idback]);
idfwd = (id + 1) % nsems;
idback = (id + nsems - 1) % nsems;
usem_open(&sems[id]);
usem_open(&sems[idfwd]);
usem_open(&sems[idback]);
waitstart();
pong_cyclic(id);
waitstart();
pong_cyclic(id);
#ifdef VERBOSE_PONG
printf("--------------------------------\n");
printf("--------------------------------\n");
#endif
pong_reciprocating(id);
pong_reciprocating(id);
#ifdef VERBOSE_PONG
printf("--------------------------------\n");
printf("--------------------------------\n");
#endif
pong_cyclic(id);
pong_cyclic(id);
usem_close(&sems[id]);
usem_close(&sems[idfwd]);
usem_close(&sems[idback]);
usem_close(&sems[id]);
usem_close(&sems[idfwd]);
usem_close(&sems[idback]);
}