// SPDX-License-Identifier: GPL-2.0+ /* * Helper functions to sync execution between parent and child processes. * * Copyright 2018, Thiago Jung Bauermann, IBM Corporation.
*/ #include <stdio.h> #include <stdbool.h> #include <semaphore.h>
/* * Information in a shared memory location for synchronization between child and * parent.
*/ struct child_sync { /* The parent waits on this semaphore. */
sem_t sem_parent;
/* If true, the child should give up as well. */ bool parent_gave_up;
/* The child waits on this semaphore. */
sem_t sem_child;
/* If true, the parent should give up as well. */ bool child_gave_up;
};
#define CHILD_FAIL_IF(x, sync) \ do { \ if (x) { \
fprintf(stderr, \ "[FAIL] Test FAILED on line %d\n", __LINE__); \
(sync)->child_gave_up = true; \
prod_parent(sync); \ return 1; \
} \
} while (0)
#define PARENT_FAIL_IF(x, sync) \ do { \ if (x) { \
fprintf(stderr, \ "[FAIL] Test FAILED on line %d\n", __LINE__); \
(sync)->parent_gave_up = true; \
prod_child(sync); \ return 1; \
} \
} while (0)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.