diff options
author | Yann Ylavic <ylavic@apache.org> | 2023-03-02 22:56:04 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2023-03-02 22:56:04 +0000 |
commit | a952454507a4dac11d2452156cb87016877feaec (patch) | |
tree | 0d08acf687ad272f2922574efc70474a1343ca83 /test/testshmconsumer.c | |
parent | 18d614dfbfd651a3c56925d06ec33891ec9ee529 (diff) | |
download | apr-a952454507a4dac11d2452156cb87016877feaec.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.
Merges r1902267 from trunk.
Merges r1908004 from 1.8.x.
Submitted by: ylavic
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1908005 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testshmconsumer.c')
-rw-r--r-- | test/testshmconsumer.c | 21 |
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) { |