Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame^] | 1 | From 2d03f99ae4de394cac0690717d96c2d884ccdae2 Mon Sep 17 00:00:00 2001 |
| 2 | From: Philip Withnall <pwithnall@endlessos.org> |
| 3 | Date: Mon, 16 Nov 2020 14:47:47 +0000 |
| 4 | Subject: [PATCH 24/29] tests: Add comment to volatile atomic tests |
| 5 | MIME-Version: 1.0 |
| 6 | Content-Type: text/plain; charset=UTF-8 |
| 7 | Content-Transfer-Encoding: 8bit |
| 8 | |
| 9 | `volatile` should not be used to indicate atomic variables, and we |
| 10 | shouldn’t encourage its use. Keep the tests, since they check that we |
| 11 | don’t emit warnings when built against incorrect old code which uses |
| 12 | `volatile`. But add a comment to stop copy/paste use of `volatile` |
| 13 | in the future. |
| 14 | |
| 15 | Signed-off-by: Philip Withnall <pwithnall@endlessos.org> |
| 16 | |
| 17 | Helps: #600 |
| 18 | Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1719] |
| 19 | --- |
| 20 | glib/tests/atomic.c | 6 ++++++ |
| 21 | 1 file changed, 6 insertions(+) |
| 22 | |
| 23 | diff --git a/glib/tests/atomic.c b/glib/tests/atomic.c |
| 24 | index 7d2459f3a..14e6e454e 100644 |
| 25 | --- a/glib/tests/atomic.c |
| 26 | +++ b/glib/tests/atomic.c |
| 27 | @@ -94,6 +94,9 @@ test_types (void) |
| 28 | res = g_atomic_pointer_compare_and_exchange (&vp_str, NULL, str); |
| 29 | g_assert_true (res); |
| 30 | |
| 31 | + /* Note that atomic variables should almost certainly not be marked as |
| 32 | + * `volatile` — see http://isvolatileusefulwiththreads.in/c/. This test exists |
| 33 | + * to make sure that we don’t warn when built against older third party code. */ |
| 34 | g_atomic_pointer_set (&vp_str_vol, NULL); |
| 35 | res = g_atomic_pointer_compare_and_exchange (&vp_str_vol, NULL, str); |
| 36 | g_assert_true (res); |
| 37 | @@ -210,6 +213,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS |
| 38 | res = g_atomic_pointer_compare_and_exchange (&vp_str, NULL, (char *) str); |
| 39 | g_assert_true (res); |
| 40 | |
| 41 | + /* Note that atomic variables should almost certainly not be marked as |
| 42 | + * `volatile` — see http://isvolatileusefulwiththreads.in/c/. This test exists |
| 43 | + * to make sure that we don’t warn when built against older third party code. */ |
| 44 | g_atomic_pointer_set (&vp_str_vol, NULL); |
| 45 | res = g_atomic_pointer_compare_and_exchange (&vp_str_vol, NULL, (char *) str); |
| 46 | g_assert_true (res); |
| 47 | -- |
| 48 | 2.30.1 |
| 49 | |