summaryrefslogtreecommitdiff
path: root/test/testshmconsumer.c
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2022-06-26 23:30:37 +0000
committerYann Ylavic <ylavic@apache.org>2022-06-26 23:30:37 +0000
commit6ed911f09d0a144f865cc12ce5267c9c507d4cb1 (patch)
tree0a91f6b5aa438caea10a851bf06316d02054fe3c /test/testshmconsumer.c
parent849781e74f9b6c2d6403ca834227167735480020 (diff)
downloadapr-6ed911f09d0a144f865cc12ce5267c9c507d4cb1.tar.gz
test/testshm: Fix synchronization of msgput/msgwait IPC functions.
* test/testshm.h(): Move (APR_INLINE) common msgput/msgwait() functions there. * test/testshm.h(msgput, msgwait): Use atomics (cas) to prevent producer and consumer from writing to the same box. * testshm.c, testshmconsumer.c, testshmproducer.c: Use common helpers. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1902267 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testshmconsumer.c')
-rw-r--r--test/testshmconsumer.c21
1 files changed, 1 insertions, 20 deletions
diff --git a/test/testshmconsumer.c b/test/testshmconsumer.c
index 6a2a3c30d..bf70e728c 100644
--- a/test/testshmconsumer.c
+++ b/test/testshmconsumer.c
@@ -30,25 +30,6 @@
#if APR_HAS_SHARED_MEMORY
-static int msgwait(int sleep_sec, int first_box, int last_box)
-{
- int i;
- int recvd = 0;
- apr_time_t start = apr_time_now();
- apr_interval_time_t sleep_duration = apr_time_from_sec(sleep_sec);
- while (apr_time_now() - start < sleep_duration) {
- for (i = first_box; i < last_box; i++) {
- if (boxes[i].msgavail && !strcmp(boxes[i].msg, MSG)) {
- recvd++;
- boxes[i].msgavail = 0; /* reset back to 0 */
- memset(boxes[i].msg, 0, 1024);
- }
- }
- apr_sleep(apr_time_from_sec(1));
- }
- return recvd;
-}
-
int main(void)
{
apr_status_t rv;
@@ -70,7 +51,7 @@ int main(void)
boxes = apr_shm_baseaddr_get(shm);
/* consume messages on all of the boxes */
- recvd = msgwait(30, 0, N_BOXES); /* wait for 30 seconds for messages */
+ recvd = msgwait(MSG, N_MESSAGES, 30, 1);
rv = apr_shm_detach(shm);
if (rv != APR_SUCCESS) {