diff options
author | Ivan Zhakov <ivan@apache.org> | 2019-10-08 11:10:32 +0000 |
---|---|---|
committer | Ivan Zhakov <ivan@apache.org> | 2019-10-08 11:10:32 +0000 |
commit | 962070b59215d49929a72bb0dce9119a15bfce6b (patch) | |
tree | ceead25e4eb73f60a951a12cb5e77aa38f9a27bd /test/testatomic.c | |
parent | f0bd008e3b8baa86170db4df0c16828dbc7938f3 (diff) | |
download | apr-962070b59215d49929a72bb0dce9119a15bfce6b.tar.gz |
apr_atomic_read64(): Fix non-atomic read on 32-bit Windows.
* atomic/win32/apr_atomic64.c
(apr_atomic_read64): Use InterlockedCompareExchange64() instead of direct
memory read.
* test/testatomic.c
(test_atomics_threaded_setread64): New test.
(test_func_set64): Helepr for test_atomics_threaded_setread64 test.
* CHANGES: Add changelog entry.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1868129 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testatomic.c')
-rw-r--r-- | test/testatomic.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/testatomic.c b/test/testatomic.c index e12136477..50ee2a9fb 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -876,6 +876,43 @@ static void test_atomics_busyloop_threaded64(abts_case *tc, void *data) ABTS_ASSERT(tc, "Failed creating threads", rv == APR_SUCCESS); } +void *APR_THREAD_FUNC test_func_set64(apr_thread_t *thd, void *data) +{ + int i; + + for (i = 0; i < 1000 * 1000; i++) { + apr_atomic_set64(&atomic_ops64, APR_UINT64_C(0x1111222233334444)); + apr_atomic_set64(&atomic_ops64, APR_UINT64_C(0x4444555566667777)); + } + + apr_thread_exit(thd, APR_SUCCESS); + return NULL; +} + +static void test_atomics_threaded_setread64(abts_case *tc, void *data) +{ + apr_status_t retval; + apr_thread_t *thread; + int i; + + apr_atomic_set64(&atomic_ops64, APR_UINT64_C(0x1111222233334444)); + + apr_thread_create(&thread, NULL, test_func_set64, NULL, p); + + for (i = 0; i < 1000 * 1000 * 2; i++) { + apr_uint64_t val = apr_atomic_read64(&atomic_ops64); + + if (val != APR_UINT64_C(0x1111222233334444) && + val != APR_UINT64_C(0x4444555566667777)) + { + ABTS_FAIL(tc, "Unexpected value"); + break; + } + } + + apr_thread_join(&retval, thread); +} + #endif /* !APR_HAS_THREADS */ abts_suite *testatomic(abts_suite *suite) @@ -916,6 +953,7 @@ abts_suite *testatomic(abts_suite *suite) abts_run_test(suite, test_atomics_threaded64, NULL); abts_run_test(suite, test_atomics_busyloop_threaded, NULL); abts_run_test(suite, test_atomics_busyloop_threaded64, NULL); + abts_run_test(suite, test_atomics_threaded_setread64, NULL); #endif return suite; |